﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using HslCommunication;
using HslCommunication.Profinet.Siemens;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using TransControlSystem.Dao;
using TransControlSystem.Enum;
using TransControlSystem.Model;
using TransControlSystem.Utils;
using TransControlSystem.ViewModel.Common;
using TransControlSystem.ViewModel.Common.Command;

namespace TransControlSystem.ViewModel
{
    /// <summary>
    /// 主监控页面后台逻辑
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
        #region 定义变量，方法，事件，线程
        #region PLC地址
        private readonly string PlcAddress = PlcHelper.GetPlcAddress();
        #endregion PLC地址
        //排序工作状态
        private bool Sortting = false;
        //删除工作状态
        private bool Deleting = false;
        //加料车是否在线标识
        private bool IsOnLine = false;
        //所有任务程序块是否为False标识
        //private bool AllTaskTagIsFalse = true;
        //当前起点位置
        private string CurrentStartPoint = "";
        //加料车在线地址
        private string FeedingTruckOnLineTagAddress;
        //要删除的任务
        TaskInfo RemoveTaskInfo = new TaskInfo();
        //模式切换验证是否通过
        private bool IsCheck = false;
        #region 页面UI控制
        /// <summary>
        /// 开始计时显示状态
        /// </summary>
        private Visibility _StartTimingStatus;
        /// <summary>
        /// 开始计时显示状态
        /// </summary>
        public Visibility StartTimingStatus
        {
            get { return _StartTimingStatus; }
            set
            {
                _StartTimingStatus = value;
                RaisePropertyChanged("StartTimingStatus");
            }
        }
        /// <summary>
        /// 计时内容
        /// </summary>
        private string _TimingContent;
        /// <summary>
        /// 计时内容
        /// </summary>
        public string TimingContent
        {
            get { return _TimingContent; }
            set
            {
                _TimingContent = value;
                RaisePropertyChanged("TimingContent");
            }
        }
        /// <summary>
        /// 计时内容显示状态
        /// </summary>
        private Visibility _TimingContentStatus;
        /// <summary>
        /// 计时内容显示状态
        /// </summary>
        public Visibility TimingContentStatus
        {
            get { return _TimingContentStatus; }
            set
            {
                _TimingContentStatus = value;
                RaisePropertyChanged("TimingContentStatus");
            }
        }
        /// <summary>
        /// 计时提示
        /// </summary>
        private string _TimingPrompt;
        /// <summary>
        /// 计时提示
        /// </summary>
        public string TimingPrompt
        {
            get { return _TimingPrompt; }
            set
            {
                _TimingPrompt = value;
                RaisePropertyChanged("TimingPrompt");
            }
        }
        /// <summary>
        /// 计时提示显示状态
        /// </summary>
        private Visibility _TimingPromptStatus;
        /// <summary>
        /// 计时提示显示状态
        /// </summary>
        public Visibility TimingPromptStatus
        {
            get { return _TimingPromptStatus; }
            set
            {
                _TimingPromptStatus = value;
                RaisePropertyChanged("TimingPromptStatus");
            }
        }

        /// <summary>
        /// 警告提示
        /// </summary>
        private string _WarningTips;
        /// <summary>
        /// 警告提示
        /// </summary>
        public string WarningTips
        {
            get { return _WarningTips; }
            set
            {
                _WarningTips = value;
                RaisePropertyChanged("WarningTips");
            }
        }
        /// <summary>
        /// 当前登录用户
        /// </summary>
        public string CurrentUserHolle
        {
            get { return LogTool.CurrentUser.UserName + "您好，当前日期："; }
        }
        #region 1#冷却室
        /// <summary>
        /// 1#冷却室背景色
        /// </summary>
        private LinearGradientBrush _CoolingRoom1Color;
        /// <summary>
        /// 1#冷却室背景色
        /// </summary>
        public LinearGradientBrush CoolingRoom1Color
        {
            get
            {
                return _CoolingRoom1Color;
            }
            set
            {
                _CoolingRoom1Color = value;
                RaisePropertyChanged("CoolingRoom1Color");
            }
        }

        /// <summary>
        /// 1#冷却室锁定按钮是否显示
        /// </summary>
        private Visibility _CoolingChamberNo1LockVisibility;
        /// <summary>
        /// 1#冷却室锁定按钮是否显示
        /// </summary>
        public Visibility CoolingChamberNo1LockVisibility
        {
            get { return _CoolingChamberNo1LockVisibility; }
            set
            {
                _CoolingChamberNo1LockVisibility = value;
                RaisePropertyChanged("CoolingChamberNo1LockVisibility");
            }
        }
        /// <summary>
        /// 1#冷却室锁定按钮命令
        /// </summary>
        public DelegateCommand CoolingChamberNo1LockCommand { get; set; }

        /// <summary>
        /// 1#冷却室解锁按钮是否显示
        /// </summary>
        private Visibility _CoolingChamberNo1UnLockVisibility;
        /// <summary>
        /// 1#冷却室解锁按钮是否显示
        /// </summary>
        public Visibility CoolingChamberNo1UnLockVisibility
        {
            get { return _CoolingChamberNo1UnLockVisibility; }
            set
            {
                _CoolingChamberNo1UnLockVisibility = value;
                RaisePropertyChanged("CoolingChamberNo1UnLockVisibility");
            }
        }
        /// <summary>
        /// 1#冷却室解锁按钮命令
        /// </summary>
        public DelegateCommand CoolingChamberNo1UnLockCommand { get; set; }
        #endregion 1#冷却室
        #region 2#冷却室
        /// <summary>
        /// 2#冷却室背景色
        /// </summary>
        private LinearGradientBrush _CoolingRoom2Color;
        /// <summary>
        /// 2#冷却室背景色
        /// </summary>
        public LinearGradientBrush CoolingRoom2Color
        {
            get
            {
                return _CoolingRoom2Color;
            }
            set
            {
                _CoolingRoom2Color = value;
                RaisePropertyChanged("CoolingRoom2Color");
            }
        }
        /// <summary>
        /// 2#冷却室锁定按钮是否显示
        /// </summary>
        private Visibility _CoolingChamberNo2LockVisibility;
        /// <summary>
        /// 2#冷却室锁定按钮是否显示
        /// </summary>
        public Visibility CoolingChamberNo2LockVisibility
        {
            get { return _CoolingChamberNo2LockVisibility; }
            set
            {
                _CoolingChamberNo2LockVisibility = value;
                RaisePropertyChanged("CoolingChamberNo2LockVisibility");
            }
        }
        /// <summary>
        /// 2#冷却室锁定按钮命令
        /// </summary>
        public DelegateCommand CoolingChamberNo2LockCommand { get; set; }

        /// <summary>
        /// 2#冷却室解锁按钮是否显示
        /// </summary>
        private Visibility _CoolingChamberNo2UnLockVisibility;
        /// <summary>
        /// 2#冷却室解锁按钮是否显示
        /// </summary>
        public Visibility CoolingChamberNo2UnLockVisibility
        {
            get { return _CoolingChamberNo2UnLockVisibility; }
            set
            {
                _CoolingChamberNo2UnLockVisibility = value;
                RaisePropertyChanged("CoolingChamberNo2UnLockVisibility");
            }
        }
        /// <summary>
        /// 2#冷却室解锁按钮命令
        /// </summary>
        public DelegateCommand CoolingChamberNo2UnLockCommand { get; set; }
        #endregion 2#冷却室
        #region 1#均质炉
        /// <summary>
        /// 1#均质炉背景色
        /// </summary>
        private LinearGradientBrush _Heating1Color;
        /// <summary>
        /// 1#均质炉背景色
        /// </summary>
        public LinearGradientBrush Heating1Color
        {
            get
            {
                return _Heating1Color;
            }
            set
            {
                _Heating1Color = value;
                RaisePropertyChanged("Heating1Color");
            }
        }
        /// <summary>
        /// 1#均质炉锁定按钮是否显示
        /// </summary>
        private Visibility _HomogenizingFurnaceNo1LockVisibility;
        /// <summary>
        /// 1#均质炉锁定按钮是否显示
        /// </summary>
        public Visibility HomogenizingFurnaceNo1LockVisibility
        {
            get { return _HomogenizingFurnaceNo1LockVisibility; }
            set
            {
                _HomogenizingFurnaceNo1LockVisibility = value;
                RaisePropertyChanged("HomogenizingFurnaceNo1LockVisibility");
            }
        }
        /// <summary>
        /// 1#均质炉锁定按钮命令
        /// </summary>
        public DelegateCommand HomogenizingFurnaceNo1LockCommand { get; set; }

        /// <summary>
        /// 1#均质炉解锁按钮是否显示
        /// </summary>
        private Visibility _HomogenizingFurnaceNo1UnLockVisibility;
        /// <summary>
        /// 1#均质炉解锁按钮是否显示
        /// </summary>
        public Visibility HomogenizingFurnaceNo1UnLockVisibility
        {
            get { return _HomogenizingFurnaceNo1UnLockVisibility; }
            set
            {
                _HomogenizingFurnaceNo1UnLockVisibility = value;
                RaisePropertyChanged("HomogenizingFurnaceNo1UnLockVisibility");
            }
        }
        /// <summary>
        /// 1#均质炉解锁按钮命令
        /// </summary>
        public DelegateCommand HomogenizingFurnaceNo1UnLockCommand { get; set; }
        #endregion 1#均质炉
        #region 2#均质炉
        /// <summary>
        /// 2#均质炉背景色
        /// </summary>
        private LinearGradientBrush _Heating2Color;
        /// <summary>
        /// 2#均质炉背景色
        /// </summary>
        public LinearGradientBrush Heating2Color
        {
            get
            {
                return _Heating2Color;
            }
            set
            {
                _Heating2Color = value;
                RaisePropertyChanged("Heating2Color");
            }
        }
        /// <summary>
        /// 2#均质炉锁定按钮是否显示
        /// </summary>
        private Visibility _HomogenizingFurnaceNo2LockVisibility;
        /// <summary>
        /// 2#均质炉锁定按钮是否显示
        /// </summary>
        public Visibility HomogenizingFurnaceNo2LockVisibility
        {
            get { return _HomogenizingFurnaceNo2LockVisibility; }
            set
            {
                _HomogenizingFurnaceNo2LockVisibility = value;
                RaisePropertyChanged("HomogenizingFurnaceNo2LockVisibility");
            }
        }
        /// <summary>
        /// 2#均质炉锁定按钮命令
        /// </summary>
        public DelegateCommand HomogenizingFurnaceNo2LockCommand { get; set; }

        /// <summary>
        /// 2#均质炉解锁按钮是否显示
        /// </summary>
        private Visibility _HomogenizingFurnaceNo2UnLockVisibility;
        /// <summary>
        /// 2#均质炉解锁按钮是否显示
        /// </summary>
        public Visibility HomogenizingFurnaceNo2UnLockVisibility
        {
            get { return _HomogenizingFurnaceNo2UnLockVisibility; }
            set
            {
                _HomogenizingFurnaceNo2UnLockVisibility = value;
                RaisePropertyChanged("HomogenizingFurnaceNo2UnLockVisibility");
            }
        }
        /// <summary>
        /// 2#均质炉解锁按钮命令
        /// </summary>
        public DelegateCommand HomogenizingFurnaceNo2UnLockCommand { get; set; }
        #endregion 2#均质炉
        #region 3#均质炉
        /// <summary>
        /// 3#均质炉背景色
        /// </summary>
        private LinearGradientBrush _Heating3Color;
        /// <summary>
        /// 3#均质炉背景色
        /// </summary>
        public LinearGradientBrush Heating3Color
        {
            get
            {
                return _Heating3Color;
            }
            set
            {
                _Heating3Color = value;
                RaisePropertyChanged("Heating3Color");
            }
        }
        /// <summary>
        /// 3#均质炉锁定按钮是否显示
        /// </summary>
        private Visibility _HomogenizingFurnaceNo3LockVisibility;
        /// <summary>
        /// 3#均质炉锁定按钮是否显示
        /// </summary>
        public Visibility HomogenizingFurnaceNo3LockVisibility
        {
            get { return _HomogenizingFurnaceNo3LockVisibility; }
            set
            {
                _HomogenizingFurnaceNo3LockVisibility = value;
                RaisePropertyChanged("HomogenizingFurnaceNo3LockVisibility");
            }
        }
        /// <summary>
        /// 3#均质炉锁定按钮命令
        /// </summary>
        public DelegateCommand HomogenizingFurnaceNo3LockCommand { get; set; }

        /// <summary>
        /// 3#均质炉解锁按钮是否显示
        /// </summary>
        private Visibility _HomogenizingFurnaceNo3UnLockVisibility;
        /// <summary>
        /// 3#均质炉解锁按钮是否显示
        /// </summary>
        public Visibility HomogenizingFurnaceNo3UnLockVisibility
        {
            get { return _HomogenizingFurnaceNo3UnLockVisibility; }
            set
            {
                _HomogenizingFurnaceNo3UnLockVisibility = value;
                RaisePropertyChanged("HomogenizingFurnaceNo3UnLockVisibility");
            }
        }
        /// <summary>
        /// 3#均质炉解锁按钮命令
        /// </summary>
        public DelegateCommand HomogenizingFurnaceNo3UnLockCommand { get; set; }
        #endregion 3#均质炉
        #region 4#均质炉
        /// <summary>
        /// 4#均质炉背景色
        /// </summary>
        private LinearGradientBrush _Heating4Color;
        /// <summary>
        /// 4#均质炉背景色
        /// </summary>
        public LinearGradientBrush Heating4Color
        {
            get
            {
                return _Heating4Color;
            }
            set
            {
                _Heating4Color = value;
                RaisePropertyChanged("Heating4Color");
            }
        }
        /// <summary>
        /// 4#均质炉锁定按钮是否显示
        /// </summary>
        private Visibility _HomogenizingFurnaceNo4LockVisibility;
        /// <summary>
        /// 4#均质炉锁定按钮是否显示
        /// </summary>
        public Visibility HomogenizingFurnaceNo4LockVisibility
        {
            get { return _HomogenizingFurnaceNo4LockVisibility; }
            set
            {
                _HomogenizingFurnaceNo4LockVisibility = value;
                RaisePropertyChanged("HomogenizingFurnaceNo4LockVisibility");
            }
        }
        /// <summary>
        /// 4#均质炉锁定按钮命令
        /// </summary>
        public DelegateCommand HomogenizingFurnaceNo4LockCommand { get; set; }

        /// <summary>
        /// 4#均质炉解锁按钮是否显示
        /// </summary>
        private Visibility _HomogenizingFurnaceNo4UnLockVisibility;
        /// <summary>
        /// 4#均质炉解锁按钮是否显示
        /// </summary>
        public Visibility HomogenizingFurnaceNo4UnLockVisibility
        {
            get { return _HomogenizingFurnaceNo4UnLockVisibility; }
            set
            {
                _HomogenizingFurnaceNo4UnLockVisibility = value;
                RaisePropertyChanged("HomogenizingFurnaceNo4UnLockVisibility");
            }
        }
        /// <summary>
        /// 4#均质炉解锁按钮命令
        /// </summary>
        public DelegateCommand HomogenizingFurnaceNo4UnLockCommand { get; set; }
        #endregion 4#均质炉
        #region 1#隔条仓
        /// <summary>
        /// 1#隔条仓背景色
        /// </summary>
        private LinearGradientBrush _SpacerStripWarehouse1Color;
        /// <summary>
        /// 1#隔条仓背景色
        /// </summary>
        public LinearGradientBrush SpacerStripWarehouse1Color
        {
            get
            {
                return _SpacerStripWarehouse1Color;
            }
            set
            {
                _SpacerStripWarehouse1Color = value;
                RaisePropertyChanged("SpacerStripWarehouse1Color");
            }
        }
        /// <summary>
        /// 1#隔条仓锁定按钮是否显示
        /// </summary>
        private Visibility _SpacerBinNo1LockVisibility;
        /// <summary>
        /// 1#隔条仓锁定按钮是否显示
        /// </summary>
        public Visibility SpacerBinNo1LockVisibility
        {
            get { return _SpacerBinNo1LockVisibility; }
            set
            {
                _SpacerBinNo1LockVisibility = value;
                RaisePropertyChanged("SpacerBinNo1LockVisibility");
            }
        }
        /// <summary>
        /// 锁定命令
        /// </summary>
        public DelegateCommand LockCommand { get; set; }

        /// <summary>
        /// 1#隔条仓解锁按钮是否显示
        /// </summary>
        private Visibility _SpacerBinNo1UnLockVisibility;
        /// <summary>
        /// 1#隔条仓解锁按钮是否显示
        /// </summary>
        public Visibility SpacerBinNo1UnLockVisibility
        {
            get { return _SpacerBinNo1UnLockVisibility; }
            set
            {
                _SpacerBinNo1UnLockVisibility = value;
                RaisePropertyChanged("SpacerBinNo1UnLockVisibility");
            }
        }
        /// <summary>
        /// 解锁命令
        /// </summary>
        public DelegateCommand UnLockCommand { get; set; }

        #endregion 1#隔条仓
        #region 2#隔条仓
        /// <summary>
        /// 2#隔条仓背景色
        /// </summary>
        private LinearGradientBrush _SpacerStripWarehouse2Color;
        /// <summary>
        /// 2#隔条仓背景色
        /// </summary>
        public LinearGradientBrush SpacerStripWarehouse2Color
        {
            get
            {
                return _SpacerStripWarehouse2Color;
            }
            set
            {
                _SpacerStripWarehouse2Color = value;
                RaisePropertyChanged("SpacerStripWarehouse2Color");
            }
        }
        /// <summary>
        /// 2#隔条仓锁定按钮是否显示
        /// </summary>
        private Visibility _SpacerBinNo2LockVisibility;
        /// <summary>
        /// 2#隔条仓锁定按钮是否显示
        /// </summary>
        public Visibility SpacerBinNo2LockVisibility
        {
            get { return _SpacerBinNo2LockVisibility; }
            set
            {
                _SpacerBinNo2LockVisibility = value;
                RaisePropertyChanged("SpacerBinNo2LockVisibility");
            }
        }

        /// <summary>
        /// 2#隔条仓解锁按钮是否显示
        /// </summary>
        private Visibility _SpacerBinNo2UnLockVisibility;
        /// <summary>
        /// 2#隔条仓解锁按钮是否显示
        /// </summary>
        public Visibility SpacerBinNo2UnLockVisibility
        {
            get { return _SpacerBinNo2UnLockVisibility; }
            set
            {
                _SpacerBinNo2UnLockVisibility = value;
                RaisePropertyChanged("SpacerBinNo2UnLockVisibility");
            }
        }
        #endregion 2#隔条仓
        #region 1#堆垛位
        /// <summary>
        /// 1#堆垛位背景色
        /// </summary>
        private LinearGradientBrush _StackingPositionNo1Color;
        /// <summary>
        /// 1#堆垛位背景色
        /// </summary>
        public LinearGradientBrush StackingPositionNo1Color
        {
            get
            {
                return _StackingPositionNo1Color;
            }
            set
            {
                _StackingPositionNo1Color = value;
                RaisePropertyChanged("StackingPositionNo1Color");
            }
        }
        /// <summary>
        /// 1#堆垛位锁定按钮是否显示
        /// </summary>
        private Visibility _StackingPositionNo1LockVisibility;
        /// <summary>
        ///1#堆垛位锁定按钮是否显示
        /// </summary>
        public Visibility StackingPositionNo1LockVisibility
        {
            get { return _StackingPositionNo1LockVisibility; }
            set
            {
                _StackingPositionNo1LockVisibility = value;
                RaisePropertyChanged("StackingPositionNo1LockVisibility");
            }
        }
        /// <summary>
        /// 1#堆垛位解锁按钮是否显示
        /// </summary>
        private Visibility _StackingPositionNo1UnLockVisibility;
        /// <summary>
        /// 1#堆垛位解锁按钮是否显示
        /// </summary>
        public Visibility StackingPositionNo1UnLockVisibility
        {
            get { return _StackingPositionNo1UnLockVisibility; }
            set
            {
                _StackingPositionNo1UnLockVisibility = value;
                RaisePropertyChanged("StackingPositionNo1UnLockVisibility");
            }
        }
        #endregion 1#堆垛位
        #region 2#堆垛位
        /// <summary>
        /// 2#堆垛位背景色
        /// </summary>
        private LinearGradientBrush _StackingPositionNo2Color;
        /// <summary>
        /// 2#堆垛位背景色
        /// </summary>
        public LinearGradientBrush StackingPositionNo2Color
        {
            get
            {
                return _StackingPositionNo2Color;
            }
            set
            {
                _StackingPositionNo2Color = value;
                RaisePropertyChanged("StackingPositionNo2Color");
            }
        }
        /// <summary>
        /// 2#堆垛位锁定按钮是否显示
        /// </summary>
        private Visibility _StackingPositionNo2LockVisibility;
        /// <summary>
        /// 2#堆垛位锁定按钮是否显示
        /// </summary>
        public Visibility StackingPositionNo2LockVisibility
        {
            get { return _StackingPositionNo2LockVisibility; }
            set
            {
                _StackingPositionNo2LockVisibility = value;
                RaisePropertyChanged("StackingPositionNo2LockVisibility");
            }
        }
        /// <summary>
        /// 2#堆垛位解锁按钮是否显示
        /// </summary>
        private Visibility _StackingPositionNo2UnLockVisibility;
        /// <summary>
        /// 2#堆垛位解锁按钮是否显示
        /// </summary>
        public Visibility StackingPositionNo2UnLockVisibility
        {
            get { return _StackingPositionNo2UnLockVisibility; }
            set
            {
                _StackingPositionNo2UnLockVisibility = value;
                RaisePropertyChanged("StackingPositionNo2UnLockVisibility");
            }
        }
        #endregion 2#堆垛位
        #region 隔条总仓
        /// <summary>
        /// 隔条总仓背景色
        /// </summary>
        private LinearGradientBrush _SpacerStripGeneralWarehouseColor;
        /// <summary>
        /// 隔条总仓背景色
        /// </summary>
        public LinearGradientBrush SpacerStripGeneralWarehouseColor
        {
            get
            {
                return _SpacerStripGeneralWarehouseColor;
            }
            set
            {
                _SpacerStripGeneralWarehouseColor = value;
                RaisePropertyChanged("SpacerStripGeneralWarehouseColor");
            }
        }
        /// <summary>
        /// 隔条总仓锁定按钮是否显示
        /// </summary>
        private Visibility _SpacerGeneralBinLockVisibility;
        /// <summary>
        /// 隔条总仓锁定按钮是否显示
        /// </summary>
        public Visibility SpacerGeneralBinLockVisibility
        {
            get { return _SpacerGeneralBinLockVisibility; }
            set
            {
                _SpacerGeneralBinLockVisibility = value;
                RaisePropertyChanged("SpacerGeneralBinLockVisibility");
            }
        }
        /// <summary>
        /// 隔条总仓解锁按钮是否显示
        /// </summary>
        private Visibility _SpacerGeneralBinUnLockVisibility;
        /// <summary>
        /// 隔条总仓解锁按钮是否显示
        /// </summary>
        public Visibility SpacerGeneralBinUnLockVisibility
        {
            get { return _SpacerGeneralBinUnLockVisibility; }
            set
            {
                _SpacerGeneralBinUnLockVisibility = value;
                RaisePropertyChanged("SpacerGeneralBinUnLockVisibility");
            }
        }
        #endregion 隔条总仓
        #region 1#解垛位
        /// <summary>
        /// 1#解垛位背景色
        /// </summary>
        private LinearGradientBrush _DestackingNo1Color;
        /// <summary>
        /// 1#解垛位背景色
        /// </summary>
        public LinearGradientBrush DestackingNo1Color
        {
            get
            {
                return _DestackingNo1Color;
            }
            set
            {
                _DestackingNo1Color = value;
                RaisePropertyChanged("DestackingNo1Color");
            }
        }
        /// <summary>
        /// 1#解垛位锁定按钮是否显示
        /// </summary>
        private Visibility _DestackingPositionNo1LockVisibility;
        /// <summary>
        /// 1#解垛位锁定按钮是否显示
        /// </summary>
        public Visibility DestackingPositionNo1LockVisibility
        {
            get { return _DestackingPositionNo1LockVisibility; }
            set
            {
                _DestackingPositionNo1LockVisibility = value;
                RaisePropertyChanged("DestackingPositionNo1LockVisibility");
            }
        }
        /// <summary>
        /// 1#解垛位解锁按钮是否显示
        /// </summary>
        private Visibility _DestackingPositionNo1UnLockVisibility;
        /// <summary>
        /// 1#解垛位解锁按钮是否显示
        /// </summary>
        public Visibility DestackingPositionNo1UnLockVisibility
        {
            get { return _DestackingPositionNo1UnLockVisibility; }
            set
            {
                _DestackingPositionNo1UnLockVisibility = value;
                RaisePropertyChanged("DestackingPositionNo1UnLockVisibility");
            }
        }
        #endregion 1#解垛位
        #region 2#解垛位
        /// <summary>
        /// 2#解垛位背景色
        /// </summary>
        private LinearGradientBrush _DestackingNo2Color;
        /// <summary>
        /// 2#解垛位背景色
        /// </summary>
        public LinearGradientBrush DestackingNo2Color
        {
            get
            {
                return _DestackingNo2Color;
            }
            set
            {
                _DestackingNo2Color = value;
                RaisePropertyChanged("DestackingNo2Color");
            }
        }
        /// <summary>
        /// 2#解垛位锁定按钮是否显示
        /// </summary>
        private Visibility _DestackingPositionNo2LockVisibility;
        /// <summary>
        /// 2#解垛位锁定按钮是否显示
        /// </summary>
        public Visibility DestackingPositionNo2LockVisibility
        {
            get { return _DestackingPositionNo2LockVisibility; }
            set
            {
                _DestackingPositionNo2LockVisibility = value;
                RaisePropertyChanged("DestackingPositionNo2LockVisibility");
            }
        }
        /// <summary>
        /// 2#解垛位解锁按钮是否显示
        /// </summary>
        private Visibility _DestackingPositionNo2UnLockVisibility;
        /// <summary>
        /// 2#解垛位解锁按钮是否显示
        /// </summary>
        public Visibility DestackingPositionNo2UnLockVisibility
        {
            get { return _DestackingPositionNo2UnLockVisibility; }
            set
            {
                _DestackingPositionNo2UnLockVisibility = value;
                RaisePropertyChanged("DestackingPositionNo2UnLockVisibility");
            }
        }
        #endregion 2#解垛位
        #region 3#解垛位
        /// <summary>
        /// 3#解垛位背景色
        /// </summary>
        private LinearGradientBrush _DestackingNo3Color;
        /// <summary>
        /// 3#解垛位背景色
        /// </summary>
        public LinearGradientBrush DestackingNo3Color
        {
            get
            {
                return _DestackingNo3Color;
            }
            set
            {
                _DestackingNo3Color = value;
                RaisePropertyChanged("DestackingNo3Color");
            }
        }
        /// <summary>
        /// 3#解垛位锁定按钮是否显示
        /// </summary>
        private Visibility _DestackingPositionNo3LockVisibility;
        /// <summary>
        /// 3#解垛位锁定按钮是否显示
        /// </summary>
        public Visibility DestackingPositionNo3LockVisibility
        {
            get { return _DestackingPositionNo3LockVisibility; }
            set
            {
                _DestackingPositionNo3LockVisibility = value;
                RaisePropertyChanged("DestackingPositionNo3LockVisibility");
            }
        }
        /// <summary>
        /// 3#解垛位解锁按钮是否显示
        /// </summary>
        private Visibility _DestackingPositionNo3UnLockVisibility;
        /// <summary>
        /// 3#解垛位解锁按钮是否显示
        /// </summary>
        public Visibility DestackingPositionNo3UnLockVisibility
        {
            get { return _DestackingPositionNo3UnLockVisibility; }
            set
            {
                _DestackingPositionNo3UnLockVisibility = value;
                RaisePropertyChanged("DestackingPositionNo3UnLockVisibility");
            }
        }
        #endregion 3#解垛位
        #region 3#隔条仓
        /// <summary>
        /// 3#隔条仓背景色
        /// </summary>
        private LinearGradientBrush _SpacerStripWarehouseNo3Color;
        /// <summary>
        /// 3#隔条仓背景色
        /// </summary>
        public LinearGradientBrush SpacerStripWarehouseNo3Color
        {
            get
            {
                return _SpacerStripWarehouseNo3Color;
            }
            set
            {
                _SpacerStripWarehouseNo3Color = value;
                RaisePropertyChanged("SpacerStripWarehouseNo3Color");
            }
        }
        /// <summary>
        /// 3#隔条仓锁定按钮是否显示
        /// </summary>
        private Visibility _SpacerBinNo3LockVisibility;
        /// <summary>
        ///3#隔条仓锁定按钮是否显示
        /// </summary>
        public Visibility SpacerBinNo3LockVisibility
        {
            get { return _SpacerBinNo3LockVisibility; }
            set
            {
                _SpacerBinNo3LockVisibility = value;
                RaisePropertyChanged("SpacerBinNo3LockVisibility");
            }
        }
        /// <summary>
        /// 3#隔条仓解锁按钮是否显示
        /// </summary>
        private Visibility _SpacerBinNo3UnLockVisibility;
        /// <summary>
        /// 3#隔条仓解锁按钮是否显示
        /// </summary>
        public Visibility SpacerBinNo3UnLockVisibility
        {
            get { return _SpacerBinNo3UnLockVisibility; }
            set
            {
                _SpacerBinNo3UnLockVisibility = value;
                RaisePropertyChanged("SpacerBinNo3UnLockVisibility");
            }
        }
        #endregion 3#隔条仓

        #region 定义菜单是否可见
        /// <summary>
        /// 功能仿真是否可见
        /// </summary>
        private Visibility _FunctionSimulationVisibility;
        /// <summary>
        /// 功能仿真是否可见
        /// </summary>
        public Visibility FunctionSimulationVisibility
        {
            get
            {
                return _FunctionSimulationVisibility;
            }
            set
            {
                _FunctionSimulationVisibility = value;
                RaisePropertyChanged("FunctionSimulationVisibility");
            }

        }
        /// <summary>
        /// 基础配置是否可见
        /// </summary>
        private Visibility _BasicInfoConfigVisibility;
        /// <summary>
        /// 基础配置是否可见
        /// </summary>
        public Visibility BasicInfoConfigVisibility
        {
            get
            {
                return _BasicInfoConfigVisibility;
            }
            set
            {
                _BasicInfoConfigVisibility = value;
                RaisePropertyChanged("BasicInfoConfigVisibility");
            }

        }
        /// <summary>
        /// 系统管理是否可见
        /// </summary>
        private Visibility _SystemManage;
        /// <summary>
        /// 系统管理是否可见
        /// </summary>
        public Visibility SystemManage
        {
            get
            {
                return _SystemManage;
            }
            set
            {
                _SystemManage = value;
                RaisePropertyChanged("SystemManage");
            }

        }
        /// <summary>
        /// 配置优先级是否可用
        /// </summary>
        private bool _PriorityConfigIsEnable;
        /// <summary>
        /// 配置优先级是否可用
        /// </summary>
        public bool PriorityConfigIsEnable
        {
            get
            {
                return _PriorityConfigIsEnable;
            }
            set
            {
                _PriorityConfigIsEnable = value;
                RaisePropertyChanged("PriorityConfigIsEnable");
            }
        }
        /// <summary>
        /// 配置程序块是否可用
        /// </summary>
        private bool _TagInfoConfigIsEnable;
        /// <summary>
        /// 配置程序块是否可用
        /// </summary>
        public bool TagInfoConfigIsEnable
        {
            get
            {
                return _TagInfoConfigIsEnable;
            }
            set
            {
                _TagInfoConfigIsEnable = value;
                RaisePropertyChanged("TagInfoConfigIsEnable");
            }
        }
        #endregion
        #region 定义按钮是否可见
        /// <summary>
        /// 是否显示启动监控按钮
        /// </summary>
        private Visibility readPlcStatus1;
        /// <summary>
        /// 是否显示启动监控按钮
        /// </summary>
        public Visibility ReadPlcStatus1
        {
            get
            {
                return readPlcStatus1;
            }
            set
            {
                readPlcStatus1 = value;
                RaisePropertyChanged("ReadPlcStatus1");
            }
        }
        /// <summary>
        /// 是否显示停止监控按钮
        /// </summary>
        private Visibility readPlcStatus2;
        /// <summary>
        /// 是否显示停止监控按钮
        /// </summary>
        public Visibility ReadPlcStatus2
        {
            get
            {
                return readPlcStatus2;
            }
            set
            {
                readPlcStatus2 = value;
                RaisePropertyChanged("ReadPlcStatus2");
            }
        }
        /// <summary>
        /// 表示启动监控灯亮
        /// </summary>
        private Visibility _LED1Light;
        /// <summary>
        /// 表示启动监控灯亮
        /// </summary>
        public Visibility LED1Light
        {
            get
            {
                return _LED1Light;
            }
            set
            {
                _LED1Light = value;
                RaisePropertyChanged("LED1Light");
            }
        }
        /// <summary>
        /// 表示启动监控灯灭
        /// </summary>
        private Visibility _LED1NotLight;
        /// <summary>
        /// 表示启动监控灯灭
        /// </summary>
        public Visibility LED1NotLight
        {
            get
            {
                return _LED1NotLight;
            }
            set
            {
                _LED1NotLight = value;
                RaisePropertyChanged("LED1NotLight");
            }
        }
        /// <summary>
        /// 是否显示加料车工作灯
        /// </summary>
        private Visibility _FeedingTruckWorkingVisibility;
        /// <summary>
        /// 是否显示加料车工作灯
        /// </summary>
        public Visibility FeedingTruckWorkingVisibility
        {
            get { return _FeedingTruckWorkingVisibility; }
            set
            {

                _FeedingTruckWorkingVisibility = value;
                RaisePropertyChanged("FeedingTruckWorkingVisibility");
            }
        }
        /// <summary>
        /// 是否显示加料车待机灯
        /// </summary>
        private Visibility _FeedingTruckNoWorkingVisibility;
        /// <summary>
        /// 是否显示加料车待机灯
        /// </summary>
        public Visibility FeedingTruckNoWorkingVisibility
        {
            get { return _FeedingTruckNoWorkingVisibility; }
            set
            {

                _FeedingTruckNoWorkingVisibility = value;
                RaisePropertyChanged("FeedingTruckNoWorkingVisibility");
            }
        }
        /// <summary>
        /// 是否显示自动按钮
        /// </summary>
        private Visibility _ShowAutomaticButton;
        /// <summary>
        /// 是否显示自动按钮
        /// </summary>
        public Visibility ShowAutomaticButton
        {
            get { return _ShowAutomaticButton; }
            set
            {

                _ShowAutomaticButton = value;
                RaisePropertyChanged("ShowAutomaticButton");
            }
        }
        /// <summary>
        /// 是否显示手动按钮
        /// </summary>
        private Visibility _ShowManualButton;
        /// <summary>
        /// 是否显示手动按钮
        /// </summary>
        public Visibility ShowManualButton
        {
            get { return _ShowManualButton; }
            set
            {
                _ShowManualButton = value;
                RaisePropertyChanged("ShowManualButton");
            }
        }
        /// <summary>
        /// 表示自动控制灯亮
        /// </summary>
        private Visibility _LED2Light;
        /// <summary>
        /// 表示自动控制灯亮 
        /// </summary>
        public Visibility LED2Light
        {
            get
            {
                return _LED2Light;
            }
            set
            {
                _LED2Light = value;
                RaisePropertyChanged("LED2Light");
            }
        }
        /// <summary>
        /// 表示自动控制灯灭
        /// </summary>
        private Visibility _LED2NotLight;
        /// <summary>
        /// 表示自动控制灯灭
        /// </summary>
        public Visibility LED2NotLight
        {
            get
            {
                return _LED2NotLight;
            }
            set
            {
                _LED2NotLight = value;
                RaisePropertyChanged("LED2NotLight");
            }
        }
        /// <summary>
        /// 是否显示通过提示
        /// </summary>
        private Visibility _IsPassVisibility;
        /// <summary>
        /// 是否显示通过提示
        /// </summary>
        public Visibility IsPassVisibility
        {
            get { return _IsPassVisibility; }
            set
            {

                _IsPassVisibility = value;
                RaisePropertyChanged("IsPassVisibility");
            }
        }
        /// <summary>
        /// 是否显示未通过提示
        /// </summary>
        private Visibility _IsNotPassVisibility;
        /// <summary>
        /// 是否显示未通过提示
        /// </summary>
        public Visibility IsNotPassVisibility
        {
            get { return _IsNotPassVisibility; }
            set
            {

                _IsNotPassVisibility = value;
                RaisePropertyChanged("IsNotPassVisibility");
            }
        }
        /// <summary>
        /// 复位按钮是否显示
        /// </summary>
        private Visibility _ResetButton;
        /// <summary>
        /// 是否显示通过提示
        /// </summary>
        public Visibility ResetButton
        {
            get { return _ResetButton; }
            set
            {

                _ResetButton = value;
                RaisePropertyChanged("ResetButton");
            }
        }
        //是否监控任务程序块，可以用来切换手动自动使用
        private bool IsAutomatic = false;
        /// <summary>
        /// 急停按钮的显示
        /// </summary>
        private Visibility _Stop;

        public Visibility Stop
        {
            get { return _Stop; }
            set
            {

                _Stop = value;
                RaisePropertyChanged("Stop");
            }
        }
        /// <summary>
        /// 停止中按钮的显示
        /// </summary>
        private Visibility _Stoping;

        public Visibility Stoping
        {
            get { return _Stoping; }
            set
            {

                _Stoping = value;
                RaisePropertyChanged("Stoping");
            }
        }
        /// <summary>
        /// 停止自动控制是否可见
        /// </summary>
        private Visibility _CloseAutomaticButton;
        /// <summary>
        /// 停止自动控制是否可见
        /// </summary>
        public Visibility CloseAutomaticButton
        {
            get { return _CloseAutomaticButton; }
            set
            {

                _CloseAutomaticButton = value;
                RaisePropertyChanged("CloseAutomaticButton");
            }
        }
        #endregion

        #endregion 页面UI控制

        #region 私有线程对象
        //监控所有程序块线程 1#
        private Thread ListeningAllTagThread = null;
        //判断加料车是否在线线程 1.1#
        private Thread ListeningFeedingTruckIsOnLineThread = null;
        //生成切换自动使用的监控列表的线程 1.2#
        //private Thread ListeningMonitoringListThread = null;
        //加料车动画移动1.3#
        private Thread ListeningFeedingTruckStatusThread = null;
        //设备颜色监控控制线程 1.4#
        private Thread ListeningEquipmentColorStatusThread = null;
        //算法条件生成线程 1.5#
        private Thread AlgorithmConditionGenerationThread = null;
        //控制模式显隐线程 1.6#
        private Thread ListeningExplicitAndImplicitControlModeThread = null;
        //加料车灯线程1.7#
        private Thread ListeningFeedingTruckControlLightThread = null;
        //倒数启动线程1.8#
        private Thread CountdownStartThread = null;
        //监控任务程序块线程 2#
        private Thread ListeningTaskThread = null;
        //监控加料车给任务服务的程序块线程 3#
        private Thread FeedingTruckForTaskThread = null;
        //删除完成的任务线程 3#
        private Thread DeleteCompletedTaskThread = null;
        #endregion

        #region PLC使用的对象
        //是否启动的标志，可以用来启动/暂停监控所有程序块
        private bool IsReadingPlc = false;
        //西门子对象
        SiemensS7Net siemens = null;
        //PLC连接对象
        OperateResult connectPlc = null;
        #endregion PLC使用的对象

        #region UI界面使用
        /// <summary>
        /// UI使用任务队列
        /// </summary>
        private ObservableCollection<AlgorithmListModel> _TaskQueue = new ObservableCollection<AlgorithmListModel>();
        /// <summary>
        /// UI使用任务队列  
        /// </summary>
        public ObservableCollection<AlgorithmListModel> TaskQueue
        {
            get
            {
                return _TaskQueue;
            }
            set
            {
                _TaskQueue = value;
                RaisePropertyChanged("TaskQueue");
            }
        }
        /// <summary>
        /// 控制模式切换监控标签队列1
        /// </summary>
        private ObservableCollection<TagInfo> _TaskTagQueue1 = new ObservableCollection<TagInfo>();
        /// <summary>
        /// 控制模式切换监控标签队列1
        /// </summary>
        public ObservableCollection<TagInfo> TaskTagQueue1
        {
            get
            {
                return _TaskTagQueue1;
            }
            set
            {
                _TaskTagQueue1 = value;
                RaisePropertyChanged("TaskTagQueue1");
            }
        }
        /// <summary>
        /// 控制模式切换监控标签队列2
        /// </summary>
        private ObservableCollection<TagInfo> _TaskTagQueue2 = new ObservableCollection<TagInfo>();
        /// <summary>
        /// 控制模式切换监控标签队列2
        /// </summary>
        public ObservableCollection<TagInfo> TaskTagQueue2
        {
            get
            {
                return _TaskTagQueue2;
            }
            set
            {
                _TaskTagQueue2 = value;
                RaisePropertyChanged("TaskTagQueue2");
            }
        }
        /// <summary>
        /// 控制模式切换监控标签队列3
        /// </summary>
        private ObservableCollection<TagInfo> _TaskTagQueue3 = new ObservableCollection<TagInfo>();
        /// <summary>
        /// 控制模式切换监控标签队列3
        /// </summary>
        public ObservableCollection<TagInfo> TaskTagQueue3
        {
            get
            {
                return _TaskTagQueue3;
            }
            set
            {
                _TaskTagQueue3 = value;
                RaisePropertyChanged("TaskTagQueue3");
            }
        }
        /// <summary>
        /// 控制模式切换监控标签队列4
        /// </summary>
        private ObservableCollection<TagInfo> _TaskTagQueue4 = new ObservableCollection<TagInfo>();
        /// <summary>
        /// 控制模式切换监控标签队列4
        /// </summary>
        public ObservableCollection<TagInfo> TaskTagQueue4
        {
            get
            {
                return _TaskTagQueue4;
            }
            set
            {
                _TaskTagQueue4 = value;
                RaisePropertyChanged("TaskTagQueue4");
            }
        }
        /// <summary>
        /// 时钟显示
        /// </summary>
        private string _TimeNow;
        /// <summary>
        /// 时钟显示
        /// </summary>
        public string TimeNow
        {
            get
            {
                return _TimeNow;
            }
            set
            {
                _TimeNow = value;
                RaisePropertyChanged("TimeNow");
            }
        }
        /// <summary>
        /// 时钟显示使用计时器
        /// </summary>
        DispatcherTimer timer = null;
        #endregion UI界面使用

        #region 数据层使用
        /// <summary>
        /// 监控队列所有程序块
        /// </summary>
        private ObservableCollection<TagInfo> _ListeningAllTagQueue = new ObservableCollection<TagInfo>();
        /// <summary>
        /// 监控队列所有程序块
        /// </summary>
        public ObservableCollection<TagInfo> ListeningAllTagQueue
        {
            get
            {
                return _ListeningAllTagQueue;
            }
            set
            {
                _ListeningAllTagQueue = value;
                RaisePropertyChanged("ListeningAllTagQueue");
            }
        }
        /// <summary>
        /// 监控队列任务程序块 
        /// </summary>
        private ObservableCollection<AlgorithmListModel> _ListeningTaskQueue = new ObservableCollection<AlgorithmListModel>();
        /// <summary>
        /// 监控队列任务程序块
        /// </summary>
        public ObservableCollection<AlgorithmListModel> ListeningTaskQueue
        {
            get
            {
                return _ListeningTaskQueue;
            }
            set
            {
                _ListeningTaskQueue = value;
                RaisePropertyChanged("ListeningTaskQueue");
            }
        }
        /// <summary>
        /// 加料车执行反馈的程序块
        /// </summary>
        private ObservableCollection<AlgorithmListModel> _FeedingTruckForTaskQueue = new ObservableCollection<AlgorithmListModel>();
        /// <summary>
        /// 加料车执行反馈的程序块
        /// </summary>
        public ObservableCollection<AlgorithmListModel> FeedingTruckForTaskQueue
        {
            get
            {
                return _FeedingTruckForTaskQueue;
            }
            set
            {
                _FeedingTruckForTaskQueue = value;
                RaisePropertyChanged("FeedingTruckForTaskQueue");
            }
        }
        #endregion 数据层使用

        #region 定义主页面执行方法

        /// <summary>
        /// 加载锁定配置
        /// </summary>
        private void LoadLockConfig()
        {
            ObservableCollection<LockModel> locks = DapperTools.QueryOc<LockModel>("select * from Lock");
            Application.Current.Dispatcher.Invoke((Action)delegate ()
            {
                for (int i = 0; i < locks.Count; i++)
                {
                    switch (locks[i].Equip)
                    {
                        case "隔条仓1#":
                            if (locks[i].LockStatus)
                            {
                                SpacerBinNo1LockVisibility = Visibility.Hidden;
                                SpacerBinNo1UnLockVisibility = Visibility.Visible;
                                SpacerStripWarehouse1Color = StatusColor.Lock();
                            }
                            else
                            {
                                SpacerBinNo1LockVisibility = Visibility.Visible;
                                SpacerBinNo1UnLockVisibility = Visibility.Hidden;
                                SpacerStripWarehouse1Color = StatusColor.Default();
                            }
                            break;
                        case "隔条仓2#":
                            if (locks[i].LockStatus)
                            {
                                SpacerBinNo2LockVisibility = Visibility.Hidden;
                                SpacerBinNo2UnLockVisibility = Visibility.Visible;
                                SpacerStripWarehouse2Color = StatusColor.Lock();
                            }
                            else
                            {
                                SpacerBinNo2LockVisibility = Visibility.Visible;
                                SpacerBinNo2UnLockVisibility = Visibility.Hidden;
                                SpacerStripWarehouse2Color = StatusColor.Default();
                            }
                            break;
                        case "堆垛位1#":
                            if (locks[i].LockStatus)
                            {
                                StackingPositionNo1LockVisibility = Visibility.Hidden;
                                StackingPositionNo1UnLockVisibility = Visibility.Visible;
                                StackingPositionNo1Color = StatusColor.Lock();
                            }
                            else
                            {
                                StackingPositionNo1LockVisibility = Visibility.Visible;
                                StackingPositionNo1UnLockVisibility = Visibility.Hidden;
                                StackingPositionNo1Color = StatusColor.Default();
                            }
                            break;
                        case "堆垛位2#":
                            if (locks[i].LockStatus)
                            {
                                StackingPositionNo2LockVisibility = Visibility.Hidden;
                                StackingPositionNo2UnLockVisibility = Visibility.Visible;
                                StackingPositionNo2Color = StatusColor.Lock();
                            }
                            else
                            {
                                StackingPositionNo2LockVisibility = Visibility.Visible;
                                StackingPositionNo2UnLockVisibility = Visibility.Hidden;
                                StackingPositionNo2Color = StatusColor.Default();
                            }
                            break;
                        case "隔条总仓":
                            if (locks[i].LockStatus)
                            {
                                SpacerGeneralBinLockVisibility = Visibility.Hidden;
                                SpacerGeneralBinUnLockVisibility = Visibility.Visible;
                                SpacerStripGeneralWarehouseColor = StatusColor.Lock();
                            }
                            else
                            {
                                SpacerGeneralBinLockVisibility = Visibility.Visible;
                                SpacerGeneralBinUnLockVisibility = Visibility.Hidden;
                                SpacerStripGeneralWarehouseColor = StatusColor.Default();
                            }
                            break;
                        case "均质炉1#":
                            if (locks[i].LockStatus)
                            {
                                HomogenizingFurnaceNo1LockVisibility = Visibility.Hidden;
                                HomogenizingFurnaceNo1UnLockVisibility = Visibility.Visible;
                                Heating1Color = StatusColor.Lock();
                            }
                            else
                            {
                                HomogenizingFurnaceNo1LockVisibility = Visibility.Visible;
                                HomogenizingFurnaceNo1UnLockVisibility = Visibility.Hidden;
                                Heating1Color = StatusColor.Default();
                            }
                            break;
                        case "均质炉2#":
                            if (locks[i].LockStatus)
                            {
                                HomogenizingFurnaceNo2LockVisibility = Visibility.Hidden;
                                HomogenizingFurnaceNo2UnLockVisibility = Visibility.Visible;
                                Heating2Color = StatusColor.Lock();
                            }
                            else
                            {
                                HomogenizingFurnaceNo2LockVisibility = Visibility.Visible;
                                HomogenizingFurnaceNo2UnLockVisibility = Visibility.Hidden;
                                Heating2Color = StatusColor.Default();
                            }
                            break;
                        case "冷却室1#":
                            if (locks[i].LockStatus)
                            {
                                CoolingChamberNo1LockVisibility = Visibility.Hidden;
                                CoolingChamberNo1UnLockVisibility = Visibility.Visible;
                                CoolingRoom1Color = StatusColor.Lock();
                            }
                            else
                            {
                                CoolingChamberNo1LockVisibility = Visibility.Visible;
                                CoolingChamberNo1UnLockVisibility = Visibility.Hidden;
                                CoolingRoom1Color = StatusColor.Default();
                            }
                            break;
                        case "均质炉3#":
                            if (locks[i].LockStatus)
                            {
                                HomogenizingFurnaceNo3LockVisibility = Visibility.Hidden;
                                HomogenizingFurnaceNo3UnLockVisibility = Visibility.Visible;
                                Heating3Color = StatusColor.Lock();
                            }
                            else
                            {
                                HomogenizingFurnaceNo3LockVisibility = Visibility.Visible;
                                HomogenizingFurnaceNo3UnLockVisibility = Visibility.Hidden;
                                Heating3Color = StatusColor.Default();
                            }
                            break;
                        case "均质炉4#":
                            if (locks[i].LockStatus)
                            {
                                HomogenizingFurnaceNo4LockVisibility = Visibility.Hidden;
                                HomogenizingFurnaceNo4UnLockVisibility = Visibility.Visible;
                                Heating4Color = StatusColor.Lock();
                            }
                            else
                            {
                                HomogenizingFurnaceNo4LockVisibility = Visibility.Visible;
                                HomogenizingFurnaceNo4UnLockVisibility = Visibility.Hidden;
                                Heating4Color = StatusColor.Default();
                            }
                            break;
                        case "冷却室2#":
                            if (locks[i].LockStatus)
                            {
                                CoolingChamberNo2LockVisibility = Visibility.Hidden;
                                CoolingChamberNo2UnLockVisibility = Visibility.Visible;
                                CoolingRoom2Color = StatusColor.Lock();
                            }
                            else
                            {
                                CoolingChamberNo2LockVisibility = Visibility.Visible;
                                CoolingChamberNo2UnLockVisibility = Visibility.Hidden;
                                CoolingRoom2Color = StatusColor.Default();
                            }
                            break;
                        case "解垛位1#":
                            if (locks[i].LockStatus)
                            {
                                DestackingPositionNo1LockVisibility = Visibility.Hidden;
                                DestackingPositionNo1UnLockVisibility = Visibility.Visible;
                                DestackingNo1Color = StatusColor.Lock();
                            }
                            else
                            {
                                DestackingPositionNo1LockVisibility = Visibility.Visible;
                                DestackingPositionNo1UnLockVisibility = Visibility.Hidden;
                                DestackingNo1Color = StatusColor.Default();
                            }
                            break;
                        case "解垛位2#":
                            if (locks[i].LockStatus)
                            {
                                DestackingPositionNo2LockVisibility = Visibility.Hidden;
                                DestackingPositionNo2UnLockVisibility = Visibility.Visible;
                                DestackingNo2Color = StatusColor.Lock();
                            }
                            else
                            {
                                DestackingPositionNo2LockVisibility = Visibility.Visible;
                                DestackingPositionNo2UnLockVisibility = Visibility.Hidden;
                                DestackingNo2Color = StatusColor.Default();
                            }
                            break;
                        case "解垛位3#":
                            if (locks[i].LockStatus)
                            {
                                DestackingPositionNo3LockVisibility = Visibility.Hidden;
                                DestackingPositionNo3UnLockVisibility = Visibility.Visible;
                                DestackingNo3Color = StatusColor.Lock();
                            }
                            else
                            {
                                DestackingPositionNo3LockVisibility = Visibility.Visible;
                                DestackingPositionNo3UnLockVisibility = Visibility.Hidden;
                                DestackingNo3Color = StatusColor.Default();
                            }
                            break;
                        case "隔条仓3#":
                            if (locks[i].LockStatus)
                            {
                                SpacerBinNo3LockVisibility = Visibility.Hidden;
                                SpacerBinNo3UnLockVisibility = Visibility.Visible;
                                SpacerStripWarehouseNo3Color = StatusColor.Lock();
                            }
                            else
                            {
                                SpacerBinNo3LockVisibility = Visibility.Visible;
                                SpacerBinNo3UnLockVisibility = Visibility.Hidden;
                                SpacerStripWarehouseNo3Color = StatusColor.Default();
                            }
                            break;
                    }
                }
            });
        }


        /// <summary>
        /// 关闭控制模式切换窗体命令
        /// </summary>
        public DelegateCommand HideControlModeSwitchingWindowCommand { get; set; }
        /// <summary>
        /// 完成任务命令
        /// </summary>
        public DelegateCommand CompleteTaskCommand { get; set; }
        /// <summary>
        /// 删除任务命令
        /// </summary>
        public DelegateCommand RemoveTaskCommand { get; set; }
        /// <summary>
        /// 检查是否通过命令
        /// </summary>
        public DelegateCommand CheckIsPassCommand { get; set; }
        public DelegateCommand Reset { get; private set; }

        /// <summary>
        /// 开启监控命令
        /// </summary>
        public DelegateCommand StartUpCommand { get; set; }
        /// <summary>
        /// 关闭监控名称
        /// </summary>
        public DelegateCommand StopCommand { get; set; }
        /// <summary>
        /// 打开窗体命令
        /// </summary>
        public DelegateCommand OpenWindowCommand { get; set; }
        /// <summary>
        /// 自动模式命令
        /// </summary>
        public DelegateCommand AutomaticModeCommand { get; set; }

        /// <summary>
        /// 停止自动控制命令
        /// </summary>
        public DelegateCommand CloseAutomaticCommand { get; set; }
        /// <summary>
        /// 手动模式命令
        /// </summary>
        public DelegateCommand ManualModeCommand { get; set; }
        /// <summary>
        /// 拍加料车紧急急停
        /// </summary>
        public DelegateCommand ButtonStopCommand { get; set; }
        /// <summary>
        /// 解除加料车紧急急停
        /// </summary>
        public DelegateCommand ButtonStopingCommand { get; set; }

        /// <summary>
        /// 退出程序命令
        /// </summary>
        public DelegateCommand ShowExitApplicationnCommand { get; set; }
        #endregion 定义主页面执行方法

        /// <summary>
        /// 验证检查是否通过命令的检测结果
        /// </summary>
        private bool IsPass = true;

        #endregion 定义变量，方法，事件，线程
        #region 远程半自动UI 命令
        /// <summary>
        /// 远程半自动模式 取消命令
        /// </summary>
        public DelegateCommand CancelCommand { get; set; }
        /// <summary>
        /// 远程半自动模式 下达命令
        /// </summary>
        public DelegateCommand ReleaseCommand { get; set; }
        /// <summary>
        /// 远程半自动模式 更改当前任务
        /// </summary>
        public DelegateCommand ChangeCurrentTaskCommand { get; set; }

        /// <summary>
        /// 远程半自动第一个任务是否选中变量
        /// </summary>
        private bool _SaTask1Checked;
        /// <summary>
        /// 远程半自动第一个任务是否选中变量
        /// </summary>
        public bool SaTask1Checked
        {
            get { return _SaTask1Checked; }
            set
            {
                _SaTask1Checked = value;
                RaisePropertyChanged("SaTask1Checked");
            }
        }
        /// <summary>
        /// 远程半自动第二个任务是否选中变量
        /// </summary>
        private bool _SaTask2Checked;
        /// <summary>
        /// 远程半自动第二个任务是否选中变量
        /// </summary>
        public bool SaTask2Checked
        {
            get { return _SaTask2Checked; }
            set
            {
                _SaTask2Checked = value;
                RaisePropertyChanged("SaTask2Checked");
            }
        }
        /// <summary>
        /// 远程半自动第三个任务是否选中变量
        /// </summary>
        private bool _SaTask3Checked;
        /// <summary>
        /// 远程半自动第三个任务是否选中变量
        /// </summary>
        public bool SaTask3Checked
        {
            get { return _SaTask3Checked; }
            set
            {
                _SaTask3Checked = value;
                RaisePropertyChanged("SaTask3Checked");
            }
        }
        /// <summary>
        /// 远程半自动第四个任务是否选中变量
        /// </summary>
        private bool _SaTask4Checked;
        /// <summary>
        /// 远程半自动第四个任务是否选中变量
        /// </summary>
        public bool SaTask4Checked
        {
            get { return _SaTask4Checked; }
            set
            {
                _SaTask4Checked = value;
                RaisePropertyChanged("SaTask4Checked");
            }
        }
        /// <summary>
        /// 远程半自动第五个任务是否选中变量
        /// </summary>
        private bool _SaTask5Checked;
        /// <summary>
        /// 远程半自动第五个任务是否选中变量
        /// </summary>
        public bool SaTask5Checked
        {
            get { return _SaTask5Checked; }
            set
            {
                _SaTask5Checked = value;
                RaisePropertyChanged("SaTask5Checked");
            }
        }
        /// <summary>
        /// 远程半自动第六个任务是否选中变量
        /// </summary>
        private bool _SaTask6Checked;
        /// <summary>
        /// 远程半自动第六个任务是否选中变量
        /// </summary>
        public bool SaTask6Checked
        {
            get { return _SaTask6Checked; }
            set
            {
                _SaTask6Checked = value;
                RaisePropertyChanged("SaTask6Checked");
            }
        }
        /// <summary>
        /// 远程半自动第七个任务是否选中变量
        /// </summary>
        private bool _SaTask7Checked;
        /// <summary>
        /// 远程半自动第七个任务是否选中变量
        /// </summary>
        public bool SaTask7Checked
        {
            get { return _SaTask7Checked; }
            set
            {
                _SaTask7Checked = value;
                RaisePropertyChanged("SaTask7Checked");
            }
        }
        /// <summary>
        /// 远程半自动第八个任务是否选中变量
        /// </summary>
        private bool _SaTask8Checked;
        /// <summary>
        /// 远程半自动第八个任务是否选中变量
        /// </summary>
        public bool SaTask8Checked
        {
            get { return _SaTask8Checked; }
            set
            {
                _SaTask8Checked = value;
                RaisePropertyChanged("SaTask8Checked");
            }
        }
        /// <summary>
        /// 远程半自动第九个任务是否选中变量
        /// </summary>
        private bool _SaTask9Checked;
        /// <summary>
        /// 远程半自动第九个任务是否选中变量
        /// </summary>
        public bool SaTask9Checked
        {
            get { return _SaTask9Checked; }
            set
            {
                _SaTask9Checked = value;
                RaisePropertyChanged("SaTask9Checked");
            }
        }
        /// <summary>
        /// 远程半自动第十个任务是否选中变量
        /// </summary>
        private bool _SaTask10Checked;
        /// <summary>
        /// 远程半自动第十个任务是否选中变量
        /// </summary>
        public bool SaTask10Checked
        {
            get { return _SaTask10Checked; }
            set
            {
                _SaTask10Checked = value;
                RaisePropertyChanged("SaTask10Checked");
            }
        }
        /// <summary>
        /// 远程半自动第 十一个任务是否选中变量
        /// </summary>
        private bool _SaTask11Checked;
        /// <summary>
        /// 远程半自动第十一个任务是否选中变量
        /// </summary>
        public bool SaTask11Checked
        {
            get { return _SaTask11Checked; }
            set
            {
                _SaTask11Checked = value;
                RaisePropertyChanged("SaTask11Checked");
            }
        }
        /// <summary>
        /// 远程半自动第十二个任务是否选中变量
        /// </summary>
        private bool _SaTask12Checked;
        /// <summary>
        /// 远程半自动第十二个任务是否选中变量
        /// </summary>
        public bool SaTask12Checked
        {
            get { return _SaTask12Checked; }
            set
            {
                _SaTask12Checked = value;
                RaisePropertyChanged("SaTask12Checked");
            }
        }
        /// <summary>
        /// 远程半自动第十三个任务是否选中变量
        /// </summary>
        private bool _SaTask13Checked;
        /// <summary>
        /// 远程半自动第十三个任务是否选中变量
        /// </summary>
        public bool SaTask13Checked
        {
            get { return _SaTask13Checked; }
            set
            {
                _SaTask13Checked = value;
                RaisePropertyChanged("SaTask13Checked");
            }
        }
        /// <summary>
        /// 远程半自动第十四个任务是否选中变量
        /// </summary>
        private bool _SaTask14Checked;
        /// <summary>
        /// 远程半自动第十四个任务是否选中变量
        /// </summary>
        public bool SaTask14Checked
        {
            get { return _SaTask14Checked; }
            set
            {
                _SaTask14Checked = value;
                RaisePropertyChanged("SaTask14Checked");
            }
        }
        /// <summary>
        /// 远程半自动第十五个任务是否选中变量
        /// </summary>
        private bool _SaTask15Checked;
        /// <summary>
        /// 远程半自动第十五个任务是否选中变量
        /// </summary>
        public bool SaTask15Checked
        {
            get { return _SaTask15Checked; }
            set
            {
                _SaTask15Checked = value;
                RaisePropertyChanged("SaTask15Checked");
            }
        }
        /// <summary>
        /// 远程半自动第十六个任务是否选中变量
        /// </summary>
        private bool _SaTask16Checked;
        /// <summary>
        /// 远程半自动第十六个任务是否选中变量
        /// </summary>
        public bool SaTask16Checked
        {
            get { return _SaTask16Checked; }
            set
            {
                _SaTask16Checked = value;
                RaisePropertyChanged("SaTask16Checked");
            }
        }
        /// <summary>
        /// 远程半自动第十七个任务是否选中变量
        /// </summary>
        private bool _SaTask17Checked;
        /// <summary>
        /// 远程半自动第十七个任务是否选中变量
        /// </summary>
        public bool SaTask17Checked
        {
            get { return _SaTask17Checked; }
            set
            {
                _SaTask17Checked = value;
                RaisePropertyChanged("SaTask17Checked");
            }
        }
        /// <summary>
        /// 远程半自动第十八个任务是否选中变量
        /// </summary>
        private bool _SaTask18Checked;
        /// <summary>
        /// 远程半自动第十八个任务是否选中变量
        /// </summary>
        public bool SaTask18Checked
        {
            get { return _SaTask18Checked; }
            set
            {
                _SaTask18Checked = value;
                RaisePropertyChanged("SaTask18Checked");
            }
        }
        /// <summary>
        /// 远程半自动第十九个任务是否选中变量
        /// </summary>
        private bool _SaTask19Checked;
        /// <summary>
        /// 远程半自动第十九个任务是否选中变量
        /// </summary>
        public bool SaTask19Checked
        {
            get { return _SaTask19Checked; }
            set
            {
                _SaTask19Checked = value;
                RaisePropertyChanged("SaTask19Checked");
            }
        }
        /// <summary>
        /// 远程半自动第二十个任务是否选中变量
        /// </summary>
        private bool _SaTask20Checked;
        /// <summary>
        /// 远程半自动第二十个任务是否选中变量
        /// </summary>
        public bool SaTask20Checked
        {
            get { return _SaTask20Checked; }
            set
            {
                _SaTask20Checked = value;
                RaisePropertyChanged("SaTask20Checked");
            }
        }
        /// <summary>
        /// 远程半自动第二十一个任务是否选中变量
        /// </summary>
        private bool _SaTask21Checked;
        /// <summary>
        /// 远程半自动第二十一个任务是否选中变量
        /// </summary>
        public bool SaTask21Checked
        {
            get { return _SaTask21Checked; }
            set
            {
                _SaTask21Checked = value;
                RaisePropertyChanged("SaTask21Checked");
            }
        }
        /// <summary>
        /// 远程半自动第二十二个任务是否选中变量
        /// </summary>
        private bool _SaTask22Checked;
        /// <summary>
        /// 远程半自动第二十二个任务是否选中变量
        /// </summary>
        public bool SaTask22Checked
        {
            get { return _SaTask22Checked; }
            set
            {
                _SaTask22Checked = value;
                RaisePropertyChanged("SaTask22Checked");
            }
        }
        /// <summary>
        /// 远程半自动第二十三个任务是否选中变量
        /// </summary>
        private bool _SaTask23Checked;
        /// <summary>
        /// 远程半自动第二十三个任务是否选中变量
        /// </summary>
        public bool SaTask23Checked
        {
            get { return _SaTask23Checked; }
            set
            {
                _SaTask23Checked = value;
                RaisePropertyChanged("SaTask23Checked");
            }
        }
        /// <summary>
        /// 远程半自动第二十四个任务是否选中变量
        /// </summary>
        private bool _SaTask24Checked;
        /// <summary>
        /// 远程半自动第二十四个任务是否选中变量
        /// </summary>
        public bool SaTask24Checked
        {
            get { return _SaTask24Checked; }
            set
            {
                _SaTask24Checked = value;
                RaisePropertyChanged("SaTask24Checked");
            }
        }
        /// <summary>
        /// 远程半自动第二十五个任务是否选中变量
        /// </summary>
        private bool _SaTask25Checked;
        /// <summary>
        /// 远程半自动第二十五个任务是否选中变量
        /// </summary>
        public bool SaTask25Checked
        {
            get { return _SaTask25Checked; }
            set
            {
                _SaTask25Checked = value;
                RaisePropertyChanged("SaTask25Checked");
            }
        }
        /// <summary>
        /// 远程半自动第二十六个任务是否选中变量
        /// </summary>
        private bool _SaTask26Checked;
        /// <summary>
        /// 远程半自动第二十六个任务是否选中变量
        /// </summary>
        public bool SaTask26Checked
        {
            get { return _SaTask26Checked; }
            set
            {
                _SaTask26Checked = value;
                RaisePropertyChanged("SaTask26Checked");
            }
        }
        /// <summary>
        /// 远程半自动第二十七个任务是否选中变量
        /// </summary>
        private bool _SaTask27Checked;
        /// <summary>
        /// 远程半自动第二十七个任务是否选中变量
        /// </summary>
        public bool SaTask27Checked
        {
            get { return _SaTask27Checked; }
            set
            {
                _SaTask27Checked = value;
                RaisePropertyChanged("SaTask27Checked");
            }
        }
        /// <summary>
        /// 远程半自动第二十八个任务是否选中变量
        /// </summary>
        private bool _SaTask28Checked;
        /// <summary>
        /// 远程半自动第二十八个任务是否选中变量
        /// </summary>
        public bool SaTask28Checked
        {
            get { return _SaTask28Checked; }
            set
            {
                _SaTask28Checked = value;
                RaisePropertyChanged("SaTask28Checked");
            }
        }
        /// <summary>
        /// 远程半自动第二十九个任务是否选中变量
        /// </summary>
        private bool _SaTask29Checked;
        /// <summary>
        /// 远程半自动第二十九个任务是否选中变量
        /// </summary>
        public bool SaTask29Checked
        {
            get { return _SaTask29Checked; }
            set
            {
                _SaTask29Checked = value;
                RaisePropertyChanged("SaTask29Checked");
            }
        }
        /// <summary>
        /// 远程半自动第三十个任务是否选中变量
        /// </summary>
        private bool _SaTask30Checked;
        /// <summary>
        /// 远程半自动第三十个任务是否选中变量
        /// </summary>
        public bool SaTask30Checked
        {
            get { return _SaTask30Checked; }
            set
            {
                _SaTask30Checked = value;
                RaisePropertyChanged("SaTask30Checked");
            }
        }
        #endregion
        #region 构造函数
        /// <summary>
        /// 初始化MainViewModel类的新实例。
        /// </summary>
        [Obsolete]
        public MainViewModel()
        {
            //初始化Command
            InitCommand();
            //初始化UI状态
            InitUI();
            //启用程序款地址配置
            TagInfoConfigIsEnable = true;
            //启用优先级配置
            PriorityConfigIsEnable = true;
            //自动设为不开启
            IsAutomatic = false;
            //初始化线程
            InitThread();
            //启动时钟
            Clock();
            //根据登录用户初始化菜单项显隐
            InitMenu();
            //加载锁定信息
            LoadLockConfig();
            //注册关闭窗体消息
            Messenger.Default.Register<NotificationMessage>(this, (nm) =>
            {
                if (nm.Notification == "RemoveTask")
                {

                    for (int x = 0; x < TaskQueue.Count; x++)
                    {
                        if (TaskQueue[x].OrderNo == RemoveTaskInfo.OrderNo)
                        {
                            RemoveTaskInfo.Id = TaskQueue[x].Id;
                            break;
                        }
                    }
                    if (RemoveTaskInfo.Id != 0)
                    {
                        string sql = @"SELECT * FROM TaskInfo WHERE Id = @Id ";
                        RemoveTaskInfo = DapperTools.Query<TaskInfo>(sql, RemoveTaskInfo);
                        //执行sql,更新任务状态
                        sql = @"DELETE TaskInfo WHERE Id = @Id ";
                        if (RemoveTaskInfo != null && DapperTools.Delete<TaskInfo>(sql, RemoveTaskInfo) > 0)
                        {
                            if (RemoveTaskInfo.TaskDesc != null)
                            {
                                LogTool.SaveLog("删除任务", "任务名称为【" + RemoveTaskInfo.TaskDesc + "】的任务被删除了。");

                            }
                            //从队列中移除任务
                            ObservableCollection<AlgorithmListModel> NewTaskS = new ObservableCollection<AlgorithmListModel>();
                            for (int x = 0; x < TaskQueue.Count; x++)
                            {
                                if (TaskQueue[x].Id != RemoveTaskInfo.Id)
                                {
                                    NewTaskS.Add(TaskQueue[x]);
                                }
                            }
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                TaskQueue = NewTaskS;
                            });
                            RemoveTaskInfo = new TaskInfo();
                        }
                    }
                    else
                    {
                        //从队列中移除任务
                        ObservableCollection<AlgorithmListModel> NewTaskS = new ObservableCollection<AlgorithmListModel>();
                        for (int x = 0; x < TaskQueue.Count; x++)
                        {
                            if (TaskQueue[x].OrderNo != RemoveTaskInfo.OrderNo)
                            {
                                NewTaskS.Add(TaskQueue[x]);
                            }
                        }
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            TaskQueue = NewTaskS;
                        });
                        RemoveTaskInfo = new TaskInfo();
                    }
                }
            });
        }

        /// <summary>
        /// 根据登录用户初始化菜单项显隐
        /// </summary>
        private void InitMenu()
        {
            if (LogTool.CurrentUser.Role == "system")
            {
                FunctionSimulationVisibility = Visibility.Visible;
                BasicInfoConfigVisibility = Visibility.Visible;
                SystemManage = Visibility.Visible;
            }
            else
            {
                FunctionSimulationVisibility = Visibility.Hidden;
                BasicInfoConfigVisibility = Visibility.Hidden;
                SystemManage = Visibility.Hidden;
            }
        }

        /// <summary>
        /// 初始化Command
        /// </summary>
        private void InitCommand()
        {
            //使用委托初始化打开窗口命令
            OpenWindowCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(OpenWindowHandler)
            };
            //使用委托初始化完成任务命令
            CompleteTaskCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(CompleteTaskHandler)
            };
            //使用委托初始化删除任务命令
            RemoveTaskCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(RemoveTaskHandler)
            };
            //使用委托初始化开启监控命令
            StartUpCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(StartUpHandler)
            };
            //使用委托初始化停止监控命令
            StopCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(StopHandler)
            };
            //使用委托拍紧急急停
            ButtonStopCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(ButtonStopHandler)
            };
            //使用委托解除紧急急停
            ButtonStopingCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(ButtonStopingHandler)
            };
            //使用委托初始化自动命令
            AutomaticModeCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(AutomaticModeHandler)
            };
            //使用委托初始化停止自动控制命令
            CloseAutomaticCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(CloseAutomaticHandler)
            };
            //使用委托初始化手动命令
            ManualModeCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(ManualModeHandler)
            };
            //使用委托初始化退出程序命令
            ShowExitApplicationnCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(ShowExitApplicationHandler)
            };
            //使用委托初始化关闭窗体命令
            HideControlModeSwitchingWindowCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(HideControlModeSwitchingWindowHandler)
            };
            //使用委托初始化检查是否通过命令
            CheckIsPassCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(CheckIsPassHandler)
            };
            //使用委托初始化检查是否通过命令
            Reset = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(ResetHandler)
            };
            //使用委托初始化锁定命令
            LockCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(LockHandler)
            };
            //使用委托初始化解锁命令
            UnLockCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(UnLockHandler)
            };
            //使用委托初始化 远程半自动模式取消命令
            CancelCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(CancelHandler)
            };
            //使用委托初始化 远程半自动模式下达命令
            ReleaseCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(ReleaseHandler)
            };
            //使用委托初始化 更改当前任务命令
            ChangeCurrentTaskCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(ChangeCurrentTaskHandler)
            };
        }
        /// <summary>
        /// 停止自动控制
        /// </summary>
        /// <param name="obj"></param>
        private void CloseAutomaticHandler(object obj)
        {
            if (IsAutomatic)
            {
                IsAutomatic = false;
                CloseAutomaticButton = Visibility.Hidden;
                ShowAutomaticButton = Visibility.Visible;
            }
        }

        /// <summary>
        /// 模式切换验证页面复位标签
        /// </summary>
        /// <param name="obj"></param>
        private void ResetHandler(object obj)
        {
            if (!IsAllPass())
            {
                TagInfo tag = GetTagInfoByTagDesc("控制系统确认任务完成");
                bool WriteResult = WriteSiemensValByAddressAndType(tag.Address, tag.ValueType, "True");
                if (WriteResult == true)
                {
                    WindowManager.ShowWarning("提示", "复位成功，请再次验证！");
                }
            }
        }
        /// <summary>
        /// 初始化UI状态
        /// </summary>
        private void InitUI()
        {
            //设置显隐
            ReadPlcStatus2 = Visibility.Hidden;
            ShowAutomaticButton = Visibility.Hidden;
            CloseAutomaticButton = Visibility.Hidden;
            ShowManualButton = Visibility.Hidden;
            LED1NotLight = Visibility.Visible;
            LED1Light = Visibility.Hidden;
            LED2NotLight = Visibility.Visible;
            LED2Light = Visibility.Hidden;
            IsPassVisibility = Visibility.Hidden;
            IsNotPassVisibility = Visibility.Hidden;
            FeedingTruckWorkingVisibility = Visibility.Hidden;
            FeedingTruckNoWorkingVisibility = Visibility.Visible;
            StartTimingStatus = Visibility.Hidden;


            //初始化时，急停按钮隐藏
            Stop = Visibility.Hidden;
            Stoping = Visibility.Hidden;
            //初始化设备颜色
            InitEquipmentColor();
        }


        /// <summary>
        /// 初始化线程（构造函数即启动线程，用状态控制线程的实际执行）
        /// 注：不要销毁线程，因为C#当中销毁线程即这个线程就无法再次使用了
        /// </summary>
        [Obsolete]
        private void InitThread()
        {
            try
            {
                //监控所有程序块1#线程
                ListeningAllTagThread = new Thread(new ThreadStart(ListeningAllTag))
                {
                    //转到后台线程
                    IsBackground = true,
                    //改变线程的优先级
                    Priority = ThreadPriority.AboveNormal
                };
                // 将创建并进入一个单线程单元
                ListeningAllTagThread.SetApartmentState(ApartmentState.STA);
                ListeningAllTagThread.Start();
                //监控加料车是否在线1.1#线程
                ListeningFeedingTruckIsOnLineThread = new Thread(new ThreadStart(ListeningFeedingTruckIsOnLine))
                {
                    //转到后台线程
                    IsBackground = true,
                    //改变线程的优先级
                    Priority = ThreadPriority.AboveNormal
                };
                ListeningFeedingTruckIsOnLineThread.SetApartmentState(ApartmentState.STA);
                ListeningFeedingTruckIsOnLineThread.Start();
                ////生成模式转换的监控列表 1.2#线程
                //ListeningMonitoringListThread = new Thread(new ThreadStart(ListeningMonitoringList))
                //{
                //    //转到后台线程
                //    IsBackground = true,
                //    //改变线程的优先级
                //    Priority = ThreadPriority.AboveNormal
                //};
                //ListeningMonitoringListThread.SetApartmentState(ApartmentState.STA);
                //ListeningMonitoringListThread.Start();
                //加料车状态监控 动画移动 控制模式显隐 1.3#线程
                ListeningFeedingTruckStatusThread = new Thread(new ThreadStart(ListeningFeedingTruckStatus))
                {
                    //转到后台线程
                    IsBackground = true,
                    //改变线程的优先级
                    Priority = ThreadPriority.AboveNormal
                };
                ListeningFeedingTruckStatusThread.SetApartmentState(ApartmentState.STA);
                ListeningFeedingTruckStatusThread.Start();
                //设备颜色监控控制 1.4#线程
                ListeningEquipmentColorStatusThread = new Thread(new ThreadStart(ListeningEquipmentColorStatus))
                {
                    //转到后台线程
                    IsBackground = true,
                    //改变线程的优先级
                    Priority = ThreadPriority.AboveNormal
                };
                ListeningEquipmentColorStatusThread.SetApartmentState(ApartmentState.STA);
                ListeningEquipmentColorStatusThread.Start();
                //算法条件生成 1.5#线程
                AlgorithmConditionGenerationThread = new Thread(new ThreadStart(AlgorithmConditionGeneration))
                {
                    //转到后台线程
                    IsBackground = true,
                    //改变线程的优先级
                    Priority = ThreadPriority.AboveNormal
                };
                AlgorithmConditionGenerationThread.SetApartmentState(ApartmentState.STA);
                AlgorithmConditionGenerationThread.Start();
                //控制模式显隐 1.6#线程
                ListeningExplicitAndImplicitControlModeThread = new Thread(new ThreadStart(ListeningExplicitAndImplicitControlMode))
                {
                    //转到后台线程
                    IsBackground = true,
                    //改变线程的优先级
                    Priority = ThreadPriority.AboveNormal
                };
                ListeningExplicitAndImplicitControlModeThread.SetApartmentState(ApartmentState.STA);
                ListeningExplicitAndImplicitControlModeThread.Start();
                //加料车忙碌灯现因控制 1.7#线程
                ListeningFeedingTruckControlLightThread = new Thread(new ThreadStart(ListeningFeedingTruckControlLight))
                {
                    //转到后台线程
                    IsBackground = true,
                    //改变线程的优先级
                    Priority = ThreadPriority.AboveNormal
                };
                ListeningFeedingTruckControlLightThread.SetApartmentState(ApartmentState.STA);
                ListeningFeedingTruckControlLightThread.Start();
                //监控任务程序块线程，2#线程
                ListeningTaskThread = new Thread(new ThreadStart(ListeningTask))
                {
                    IsBackground = true,
                    Priority = ThreadPriority.AboveNormal
                };
                ListeningTaskThread.SetApartmentState(ApartmentState.STA);
                ListeningTaskThread.Start();
                //执行任务线程,3#线程
                FeedingTruckForTaskThread = new Thread(new ThreadStart(ExecuteTask))
                {
                    IsBackground = true,
                    Priority = ThreadPriority.AboveNormal
                };
                FeedingTruckForTaskThread.SetApartmentState(ApartmentState.STA);
                FeedingTruckForTaskThread.Start();
                //删除完成的任务线程 3.1#线程
                DeleteCompletedTaskThread = new Thread(new ThreadStart(DeleteCompletedTask))
                {
                    IsBackground = true,
                    Priority = ThreadPriority.AboveNormal
                };
                DeleteCompletedTaskThread.SetApartmentState(ApartmentState.STA);
                DeleteCompletedTaskThread.Start();
            }
            catch (Exception e)
            {
                LogTool.SaveSysLog(e.Message, "初始化线程异常");
            }
        }

        /// <summary>
        /// 每秒刷新时钟
        /// </summary>
        private void Clock()
        {
            timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(1)
            };
            timer.Tick += (o, a) =>
            {
                TimeNow = DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss dddd");
            };

            timer.Start();
        }

        #endregion 构造函数

        #region 主页面的执行方法
        /// <summary>
        /// 开启监控处理程序
        /// </summary>
        /// <param name="obj">参数</param>
        private void StartUpHandler(object obj)
        {
            try
            {
                WarningTips = "";
                //隐藏启动监控按钮
                ReadPlcStatus1 = Visibility.Hidden;
                //显示停止监控按钮
                ReadPlcStatus2 = Visibility.Visible;
                //显示自动控制按钮
                ShowAutomaticButton = Visibility.Visible;
                // 西门子PLC通讯，指定PLC的ip地址和端口号
                siemens = new SiemensS7Net(SiemensPLCS.S1500, PlcAddress);
                // 连接对象
                connectPlc = siemens.ConnectServer();
                if (!connectPlc.IsSuccess)
                {
                    ReadPlcStatus1 = Visibility.Visible;
                    ReadPlcStatus2 = Visibility.Hidden;
                    ShowAutomaticButton = Visibility.Hidden;
                    WindowManager.ShowWarning("警告", "连接PLC失败，请检查网络通讯是否正常！（启动监控时）");
                }
                else
                {
                    IsReadingPlc = true;//允许监控标签，执行1#线程
                    TagInfoConfigIsEnable = !IsReadingPlc;
                    LED1NotLight = Visibility.Hidden;
                    LED1Light = Visibility.Visible;//LED灯1亮
                    //启动监控后，根据急停标签的值，显示急停按钮
                    TagInfo tag = GetTagInfoByTagDesc("加料车急停");
                    if (tag.Value == "False") //0是未停止状态，显示急停按钮
                    {
                        Stop = Visibility.Visible;
                        Stoping = Visibility.Hidden;
                    }
                    else if (tag.Value == "True")//1是停止状态，显示急停中按钮
                    {
                        Stop = Visibility.Hidden;
                        Stoping = Visibility.Visible;
                    }
                    else
                    {
                        Stop = Visibility.Hidden;
                        Stoping = Visibility.Hidden;
                    }

                    //初始化倒计时线程
                    CountdownStartThread = new Thread(new ThreadStart(CountdownStartThreadFun))
                    {
                        //转到后台线程
                        IsBackground = true,
                        //改变线程的优先级
                        Priority = ThreadPriority.AboveNormal
                    };
                    CountdownStartThread.SetApartmentState(ApartmentState.STA);
                    CountdownStartThread.Start();
                }
            }
            catch (Exception e)
            {
                LogTool.SaveSysLog(e.Message, "开启监控异常");
            }
        }
        /// <summary>
        /// 启动倒数计数器
        /// </summary>
        private void CountdownStartThreadFun()
        {
            Application.Current.Dispatcher.Invoke((Action)delegate ()
            {
                var dispatcher = App.Current.MainWindow.Dispatcher;
                Task.Factory.StartNew(() =>
                {
                    TimingContentStatus = Visibility.Hidden;
                    StartTimingStatus = Visibility.Visible;
                    TimingPrompt = "尊敬的用户，本系统正在初始化，请稍等,谢谢！";
                    TimingPromptStatus = Visibility.Visible;
                    Thread.Sleep(1000);
                    dispatcher.Invoke((Action)delegate ()
                    {
                        TimingPromptStatus = Visibility.Hidden;
                        TimingContent = "3";
                        TimingContentStatus = Visibility.Visible;
                    });
                    Thread.Sleep(1000);
                    dispatcher.Invoke((Action)delegate ()
                    {
                        TimingContent = "2";
                    });
                    Thread.Sleep(1000);
                    dispatcher.Invoke((Action)delegate ()
                    {
                        TimingContent = "1";
                    });
                    Thread.Sleep(1000);
                    dispatcher.Invoke((Action)delegate ()
                    {
                        TimingContentStatus = Visibility.Hidden;
                        TimingPrompt = "尊敬的用户，抱歉让您久等了，系统启动初始化完成,可以正常使用了!";
                        TimingPromptStatus = Visibility.Visible;
                    });
                    Thread.Sleep(1000);
                    dispatcher.Invoke((Action)delegate ()
                    {
                        StartTimingStatus = Visibility.Hidden;
                    });
                });
            });
        }
        /// <summary>
        /// 停止监控处理程序
        /// </summary>
        /// <param name="obj">参数</param>
        private void StopHandler(object obj)
        {
            ShowAutomaticButton = Visibility.Hidden;//隐藏自动控制按钮
            ReadPlcStatus1 = Visibility.Visible;//显示启动监控按钮
            ReadPlcStatus2 = Visibility.Hidden;//隐藏停止监控按钮
            LED1NotLight = Visibility.Visible;
            LED1Light = Visibility.Hidden;//LED灯1灭
            LED2NotLight = Visibility.Visible;
            LED2Light = Visibility.Hidden;//LED灯2灭
            //停止监控时隐藏急停按钮
            Stop = Visibility.Hidden;
            Stoping = Visibility.Hidden;

            IsAutomatic = false;
            PriorityConfigIsEnable = !IsAutomatic;
            IsReadingPlc = false;
            TagInfoConfigIsEnable = !IsReadingPlc;
            siemens.ConnectClose();
            InitEquipmentColor();
        }
        /// <summary>
        /// 加料车紧急急停处理程序
        /// </summary>
        /// <param name="obj"></param>
        private void ButtonStopHandler(object obj)
        {
            TagInfo tag = GetTagInfoByTagDesc("加料车急停");
            if (tag.Value == "False" && IsAutomatic == true) //0是未停止状态
            {
                bool WriteResult = WriteSiemensValByAddressAndType(tag.Address, tag.ValueType, "True");
                if (WriteResult == true)
                {
                    Stop = Visibility.Hidden;
                    Stoping = Visibility.Visible;
                }
            }


        }
        /// <summary>
        /// 加料车解除紧急急停处理程序
        /// </summary>
        /// <param name="obj"></param>
        private void ButtonStopingHandler(object obj)
        {
            TagInfo tag = GetTagInfoByTagDesc("加料车急停");
            if (tag.Value == "True") //1是未停止状态
            {
                bool WriteResult = WriteSiemensValByAddressAndType(tag.Address, tag.ValueType, "False");
                if (WriteResult == true)
                {
                    Stop = Visibility.Visible;
                    Stoping = Visibility.Hidden;
                }
            }
        }
        /// <summary>
        /// 检测当前主界面任务队列列表中是否有未完成的任务
        /// </summary>
        /// <returns></returns>
        private bool IsNotHaveCompletedTask()
        {
            bool IsNotHaveCompletedTaskValue = true;
            for (int i = 0; i < TaskQueue.Count; i++)
            {
                if (TaskQueue[i].Status != "已完成")
                {
                    IsNotHaveCompletedTaskValue = false;
                    break;
                }
            }
            return IsNotHaveCompletedTaskValue;
        }

        /// <summary>
        /// 启动自动控制处理程序
        /// </summary>
        /// <param name="obj">参数</param>
        private void AutomaticModeHandler(object obj)
        {
            try
            {
                //如果加料车在线
                if (IsOnLine)
                {
                    TagInfo tag = GetTagInfoByTagDesc("自动控制使能");
                    if (tag.Value == "True")
                    {
                        if (IsNotHaveCompletedTask() && IsAllPass())
                        {
                            LogTool.SaveLog("控制模式切换", "启动自动控制！");
                            ReadPlcStatus2 = Visibility.Hidden;//隐藏停止监控按钮
                            ShowAutomaticButton = Visibility.Hidden;//隐藏启动控制按钮
                                                                    //ShowManualButton = Visibility.Visible;//显示停止控制按钮，允许电脑端停止自动控制
                            ShowManualButton = Visibility.Hidden;//隐藏停止控制按钮，不让电脑端可以停止自动控制
                            IsAutomatic = true;//允许生成任务，执行2#线程和3#线程
                            CloseAutomaticButton = Visibility.Visible;
                            PriorityConfigIsEnable = !IsAutomatic;
                        }
                        //如果任务队列不为空则弹出控制模式切换窗体
                        else
                        {
                            //如果已经验证通过，则不必再验证
                            if (IsCheck && IsAllPass())
                            {
                                LogTool.SaveLog("控制模式切换", "启动自动控制！");
                                ReadPlcStatus2 = Visibility.Hidden;//隐藏停止监控按钮
                                ShowAutomaticButton = Visibility.Hidden;//隐藏启动控制按钮
                                //ShowManualButton = Visibility.Visible;//显示停止控制按钮，允许电脑端停止自动控制
                                ShowManualButton = Visibility.Hidden;//隐藏停止控制按钮，不让电脑端可以停止自动控制
                                IsAutomatic = true;//允许生成任务，执行2#线程和3#线程
                                CloseAutomaticButton = Visibility.Visible;
                                PriorityConfigIsEnable = !IsAutomatic;
                            }
                            else
                            {
                                //隐藏停止监控按钮
                                ReadPlcStatus2 = Visibility.Hidden;
                                //隐藏启动控制按钮
                                ReadPlcStatus1 = Visibility.Hidden;
                                //显示启动控制按钮
                                ShowAutomaticButton = Visibility.Visible;
                                //隐藏停止控制按钮，不让电脑端可以停止自动控制
                                ShowManualButton = Visibility.Hidden;
                                //不允许启动2号3号线程
                                IsAutomatic = false;
                                CloseAutomaticButton = Visibility.Hidden;
                                //是否禁用配置
                                PriorityConfigIsEnable = !IsAutomatic;
                                //加载控制模式列表
                                LoadControlModelList();
                                ResetButton = Visibility.Hidden;
                                //打开控制模式切换窗体
                                WindowManager.Show("ControlModeSwitchingWindow", null);
                                
                            }
                        }
                    }
                    else
                    {
                        WindowManager.ShowWarning("警告", "加料车不允许自动控制！");
                    }
                }
                else
                {
                    WindowManager.ShowWarning("警告", "加料车不在线无法开启自动控制！");
                }
            }
            catch (Exception e)
            {
                LogTool.SaveSysLog(e.Message, "启动自动监控异常");
            }
        }
        /// <summary>
        /// 停止自动控制（也就是切换为手动控制）处理程序
        /// </summary>
        /// <param name="obj">参数</param>
        private void ManualModeHandler(object obj)
        {
            //如果任务队列为空则可以停止自动控制
            if ((TaskQueue == null || TaskQueue.Count == 0) && IsAllPass())
            {
                ReadPlcStatus2 = Visibility.Visible;//显示停止监控按钮
                ShowAutomaticButton = Visibility.Visible;//显示启动控制按钮
                ShowManualButton = Visibility.Hidden;//隐藏停止自动控制按钮
                IsAutomatic = false;
                PriorityConfigIsEnable = !IsAutomatic;
            }
        }
        /// <summary>
        /// 完成任务处理程序
        /// </summary>
        /// <param name="obj">参数</param>
        private void CompleteTaskHandler(object obj)
        {
            TaskInfo taskInfo = new TaskInfo();
            taskInfo.Id = int.Parse(obj.ToString());
            taskInfo.Status = "已完成";
            taskInfo.EndTime = DateTime.Now;
            string sql = @"update TaskInfo 
                            set Status = @Status,
                            EndTime = @EndTime
                            where Id = @Id ";
            //执行sql,更新任务状态
            if (DapperTools.Update<TaskInfo>(sql, taskInfo) > 0)
            {
                TagInfo SystemConfirmCompleteTag = GetTagInfoByTagDesc("控制系统确认任务完成");
                bool ConfirmCompletionWriteResult = WriteSiemensValByAddressAndType(SystemConfirmCompleteTag.Address, SystemConfirmCompleteTag.ValueType, "True");
                if (ConfirmCompletionWriteResult)
                {
                    ////从队列中移除任务
                    ObservableCollection<AlgorithmListModel> NewTaskS = new ObservableCollection<AlgorithmListModel>();
                    for (int x = 0; x < TaskQueue.Count; x++)
                    {
                        if (TaskQueue[x].Id != taskInfo.Id)
                        {
                            NewTaskS.Add(TaskQueue[x]);
                        }
                    }
                    Thread.Sleep(10);
                    Application.Current.Dispatcher.Invoke((Action)delegate ()
                    {
                        TaskQueue = NewTaskS;
                    });
                }
            }
        }

        /// <summary>
        /// 删除任务处理程序
        /// </summary>
        /// <param name="obj">参数</param>
        private void RemoveTaskHandler(object obj)
        {
            //RemoveTaskInfo.Id = int.Parse(obj.ToString());
            RemoveTaskInfo.OrderNo = long.Parse(obj.ToString());
            WindowManager.ConfirmShow("删除任务", "您确定要删除此任务吗？", "RemoveTask");
        }

        /// <summary>
        /// 加载控制模式转换标签列表
        /// </summary>
        private void LoadControlModelList()
        {
            try
            {
                if (IsReadingPlc && ListeningAllTagQueue.Count > 0 && IsOnLine)
                {
                    //第一监控列表
                    TaskTagQueue1 = new ObservableCollection<TagInfo>();
                    //第二监控列表
                    TaskTagQueue3 = new ObservableCollection<TagInfo>();
                    //第三监控列表
                    TaskTagQueue4 = new ObservableCollection<TagInfo>();
                    for (int i = 0; i < ListeningAllTagQueue.Count; i++)
                    {

                        //生成切换自动使用的监控列表

                        if (ListeningAllTagQueue[i].Type == 2)//执行任务对应的30个标签
                        {
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                TaskTagQueue1.Add(ListeningAllTagQueue[i]);
                            });
                        }
                        else if (ListeningAllTagQueue[i].Type == 3 && (ListeningAllTagQueue[i].TagDesc == "任务指令执行完成" || ListeningAllTagQueue[i].TagDesc == "控制系统确认任务完成"))
                        {
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                TaskTagQueue3.Add(ListeningAllTagQueue[i]);
                            });
                        }
                        else if (ListeningAllTagQueue[i].Type == 3 && ListeningAllTagQueue[i].TagDesc == "执行完成的标签名")
                        {
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                TaskTagQueue4.Add(ListeningAllTagQueue[i]);
                            });
                        }

                    }
                }
            }
            catch (Exception e)
            {
                LogTool.SaveSysLog(e.Message, "监控手动转自动列表异常");
                WindowManager.ShowWarning("警告", "监控手动转自动列表异常");
                return;
            }
        }
        /// <summary>
        /// 检查是否通过命令处理程序
        /// </summary>
        /// <param name="obj">参数</param>
        private void CheckIsPassHandler(object obj)
        {
            
            LoadControlModelList();
            //验证通过
            if (IsAllPass())
            {
                IsPassVisibility = Visibility.Visible;
                IsNotPassVisibility = Visibility.Hidden;
                IsCheck = true;
            }
            //验证不通过
            else
            {
                IsPassVisibility = Visibility.Hidden;
                IsNotPassVisibility = Visibility.Visible;
                IsCheck = false;
                ResetButton = Visibility.Visible;

            }
        }
        /// <summary>
        /// 锁定命令处理程序
        /// </summary>
        /// <param name="obj"></param>
        private void LockHandler(object obj)
        {
            if (!IsAutomatic)
            {
                LockModel lockModel = new LockModel() { Equip = obj.ToString() };
                string sql = @"update Lock
                           set LockStatus = 1 
                           where Equip = @Equip
                           ";
                int updateResult = DapperTools.Update<LockModel>(sql, lockModel);
                if (updateResult > 0)
                {
                    LoadLockConfig();
                }
            }
            else
            {
                WindowManager.ShowWarning("提示", "自动控制模式下不可以锁定设备，请先解除自动控制！");
            }
        }
        /// <summary>
        /// 解锁命令处理程序
        /// </summary>
        /// <param name="obj"></param>
        private void UnLockHandler(object obj)
        {
            if (!IsAutomatic)
            {
                LockModel lockModel = new LockModel() { Equip = obj.ToString() };
                string sql = @"update Lock
                           set LockStatus = 0 
                           where Equip = @Equip
                           ";
                int updateResult = DapperTools.Update<LockModel>(sql, lockModel);
                if (updateResult > 0)
                {
                    LoadLockConfig();
                }
            }
            else
            {
                WindowManager.ShowWarning("提示", "自动控制模式下不可以解除锁定设备，请先解除自动控制！");
            }

        }


        /// <summary>
        /// 打开窗口处理程序
        /// </summary>
        /// <param name="obj">参数：一般用作传递判断参数，根据判断参数来判断打开哪个窗体</param>
        private void OpenWindowHandler(object obj)
        {
            switch (obj.ToString())
            {
                //任务查询
                case "TaskQueryWindow":
                    WindowManager.ShowDialog("TaskQueryWindow", null);
                    break;
                //通讯测试
                case "CommunicationTestWindow":
                    WindowManager.ShowDialog("CommunicationTestWindow", null);
                    break;
                //模拟演示
                case "DemoTestWindow":
                    WindowManager.ShowDialog("DemoTestWindow", null);
                    break;
                //PLC的IP地址配置
                case "PlcAddressConfigWindow":
                    WindowManager.ShowDialog("PlcAddressConfigWindow", null);
                    break;
                //PLC的标签信息配置
                case "TagInfoConfigWindow":
                    WindowManager.ShowDialog("TagInfoConfigWindow", null);
                    break;
                //铝垛PLC的标签信息配置
                case "StackTagInfoConfigWindow":
                    WindowManager.ShowDialog("StackTagInfoConfigWindow", null);
                    break;
                //算法优先级配置
                case "PriorityConfigWindow":
                    WindowManager.ShowDialog("PriorityConfigWindow", null);
                    break;
                //用户信息管理
                case "UserManagementWindow":
                    WindowManager.ShowDialog("UserManagementWindow", null);
                    break;
                //操作日志
                case "LogWindow":
                    WindowManager.ShowDialog("LogWindow", null);
                    break;
                //远程半自动
                case "RemoteSemiAutomaticWindows":
                    WindowManager.ShowDialog("RemoteSemiAutomaticWindows", null);
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 打开退出程序窗口处理程序
        /// </summary>
        /// <param name="obj">参数</param>
        private void ShowExitApplicationHandler(object obj)
        {
            WindowManager.ShowDialog("ExitAppliacationWindow", null);
        }

        /// <summary>
        /// 关闭窗体方法处理程序
        /// </summary>
        /// <param name="obj">参数</param>
        private void HideControlModeSwitchingWindowHandler(object obj)
        {
            //MonitorThread.Abort();
            Messenger.Default.Send<NotificationMessage>(new NotificationMessage(this, "CloseWindowsBoundToHideControlModeSwitchingWindow"));
        }


        #endregion

        #region 未启动线程时的相关方法
        /// <summary>
        /// 初始化设备颜色，通过静态枚举类修改设备颜色
        /// </summary>
        private void InitEquipmentColor()
        {
            //1#冷却室
            CoolingRoom1Color = StatusColor.Default();
            //2#冷却室
            CoolingRoom2Color = StatusColor.Default();
            //1#均质炉
            Heating1Color = StatusColor.Default();
            //2#均质炉
            Heating2Color = StatusColor.Default();
            //3#均质炉
            Heating3Color = StatusColor.Default();
            //4#均质炉
            Heating4Color = StatusColor.Default();
            //1#隔条仓
            SpacerStripWarehouse1Color = StatusColor.Default();
            //2#隔条仓
            SpacerStripWarehouse2Color = StatusColor.Default();
            //1#堆垛位
            StackingPositionNo1Color = StatusColor.Default();
            //2#堆垛位
            StackingPositionNo2Color = StatusColor.Default();
            //隔条总仓
            SpacerStripGeneralWarehouseColor = StatusColor.Default();
            //1#解垛位
            DestackingNo1Color = StatusColor.Default();
            //2#解垛位
            DestackingNo2Color = StatusColor.Default();
            //3#解垛位
            DestackingNo3Color = StatusColor.Default();
            //3#隔条仓
            SpacerStripWarehouseNo3Color = StatusColor.Default();
        }


        #endregion 未启动线程时的相关方法

        #region 1#线程的相关方法,1#线程的主要任务是与PLC做通讯，实时读取值

        /// <summary>
        /// 监控所有程序块的方法
        /// </summary>
        private void ListeningAllTag()
        {
            //加载所有标签列表
            ListeningAllTagQueue = DapperTools.QueryOc<TagInfo>("SELECT * FROM TagInfo WHERE IsEnable = 1 ORDER BY Id");
            Thread.Sleep(5000);
            while (true)
            {
                if (IsReadingPlc)
                {
                    if (ListeningAllTagQueue.Count > 0)
                    {
                        if (TaskQueue.Count == 0)
                        {
                            //加载数据库中未完成的所有任务
                            TaskQueue = DapperTools.QueryOc<AlgorithmListModel>("SELECT * FROM TaskInfo WHERE Status != '已完成' AND IsDelete = 0 ORDER BY OrderNo");
                        }
                        for (int i = 0; i < ListeningAllTagQueue.Count; i++)
                        {
                            if (connectPlc.IsSuccess)
                            {
                                string TagValue = GetSiemensValByAddressAndType(ListeningAllTagQueue[i].Address, ListeningAllTagQueue[i].ValueType);
                                if (ListeningAllTagQueue[i].Value != TagValue)
                                {
                                    ListeningAllTagQueue[i].Value = TagValue;
                                }
                            }
                            else
                            {
                                Application.Current.Dispatcher.Invoke((Action)delegate ()
                                {
                                    IsReadingPlc = false;
                                    IsOnLine = false;
                                    IsAutomatic = false;
                                    TagInfoConfigIsEnable = !IsAutomatic;
                                    ReadPlcStatus1 = Visibility.Visible;
                                    ReadPlcStatus2 = Visibility.Hidden;
                                    ShowAutomaticButton = Visibility.Hidden;
                                    WarningTips = "连接PLC失败，请检查网络通讯是否正常！（读取所有标签时）";
                                });
                                break;
                            }
                        }
                    }
                }
                //else
                //{
                //    Application.Current.Dispatcher.Invoke((Action)delegate ()
                //    {
                //        IsReadingPlc = false;
                //        IsOnLine = false;
                //        IsAutomatic = false;
                //        TagInfoConfigIsEnable = !IsAutomatic;
                //        ReadPlcStatus1 = Visibility.Visible;
                //        ReadPlcStatus2 = Visibility.Hidden;
                //        ShowAutomaticButton = Visibility.Hidden;
                //        WarningTips = "连接PLC失败，请检查网络通讯是否正常！（未启动监控时）";
                //    });
                //}
                Thread.Sleep(100);
            }
        }


        /// <summary>
        /// 监控加料车是否在线线程
        /// </summary>
        private void ListeningFeedingTruckIsOnLine()
        {
            int n = 0;
            while (true)
            {
                try
                {
                    if (IsReadingPlc && ListeningAllTagQueue.Count > 0)
                    {
                        TagInfo FeedingTruckOnLIneTagInfoCondition = new TagInfo();
                        FeedingTruckOnLIneTagInfoCondition.TagDesc = "加料车在线";
                        FeedingTruckOnLineTagAddress = DapperTools.Query<TagInfo>("select * from TagInfo WHERE TagDesc = @TagDesc", FeedingTruckOnLIneTagInfoCondition).Address;
                        string FeedingTruckOnLIneTagValue = siemens.ReadBool(FeedingTruckOnLineTagAddress).Content.ToString();
                        if (FeedingTruckOnLIneTagValue == "False")
                        {
                            //为防止系统误报，连续三次检验加料车不在线，才报连接失败
                            n++;
                            if (n >= 3)
                            {
                                Application.Current.Dispatcher.Invoke((Action)delegate ()
                                {
                                    IsOnLine = false;
                                    IsAutomatic = false;
                                    TagInfoConfigIsEnable = !IsAutomatic;
                                    ReadPlcStatus1 = Visibility.Visible;
                                    ReadPlcStatus2 = Visibility.Hidden;
                                    WarningTips = "连接PLC失败，请检查网络通讯是否正常！（检测加料车在线时）";
                                });
                                LogTool.SaveSysLog("加料车掉线" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "加料车掉线");
                                n = 0;
                            }
                        }
                        else
                        {
                            //获取自动控制标签值
                            TagInfo IsAutoTag = GetTagInfoByTagDesc("自动控制使能");
                            //如果是允许自动控制并且已启动自动控制
                            if (IsAutoTag.Value == "True" && IsAutomatic == true)
                            {
                                //获取第一个未完成任务
                                AlgorithmListModel FirstTask = GetFirstTaks();
                                //如果第一个未完成任务不为空，并且可以继续，则继续自动控制
                                if (FirstTask != null && IsContinue())
                                {
                                    Application.Current.Dispatcher.Invoke((Action)delegate ()
                                    {
                                        ReadPlcStatus1 = Visibility.Hidden;
                                        ReadPlcStatus2 = Visibility.Hidden;
                                    });
                                }
                                //cx于1月6日现场调试注释
                                //else
                                //{
                                //    Application.Current.Dispatcher.Invoke((Action)delegate ()
                                //    {
                                //        IsAutomatic = true;
                                //        TagInfoConfigIsEnable = !IsAutomatic;
                                //        ReadPlcStatus1 = Visibility.Hidden;
                                //        ReadPlcStatus2 = Visibility.Hidden;
                                //    });
                                //}
                                Application.Current.Dispatcher.Invoke((Action)delegate ()
                                {
                                    IsOnLine = true;
                                    WarningTips = "";
                                });
                            }
                            else
                            {
                                Application.Current.Dispatcher.Invoke((Action)delegate ()
                                {
                                    IsOnLine = true;
                                    IsAutomatic = false;
                                    TagInfoConfigIsEnable = !IsAutomatic;
                                    ReadPlcStatus1 = Visibility.Hidden;
                                    ReadPlcStatus2 = Visibility.Visible;
                                    ShowAutomaticButton = Visibility.Visible;
                                    WarningTips = "";
                                });
                            }
                            n = 0;
                        }
                    }
                    Thread.Sleep(5000);
                }
                catch (Exception e)
                {
                    LogTool.SaveSysLog(e.Message, "监控加料车是否在线异常");
                }
            }
        }
        /// <summary>
        /// 判断是否继续
        /// </summary>
        /// <returns></returns>
        private bool IsContinue()
        {
            AlgorithmListModel FirstTask = GetFirstTaks();
            TagInfo SuccessTaskNoTagInfoCondition = new TagInfo();
            SuccessTaskNoTagInfoCondition.TagDesc = "执行完成的标签名";
            string SuccessTaskNoAddress = DapperTools.Query<TagInfo>("select * from TagInfo WHERE TagDesc = @TagDesc", SuccessTaskNoTagInfoCondition).Address;
            string SuccessTaskInfo = siemens.ReadInt32(SuccessTaskNoAddress).Content.ToString();
            if (FirstTask != null || SuccessTaskInfo != null &&
               IsComplete(SuccessTaskInfo, FirstTask))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 加料车状态监控 动画移动 控制模式显隐线程 1.3#
        /// </summary>
        private void ListeningFeedingTruckStatus()
        {
            while (true)
            {
                try
                {
                    if (IsReadingPlc && ListeningAllTagQueue.Count > 0 && IsOnLine)
                    {
                        TagInfo tagInfo = GetTagInfoByTagDesc("加料车位置");
                        string Point = "";
                        if (tagInfo.Value != null && tagInfo.Value != "0")
                        {
                            switch (tagInfo.Value)
                            {
                                case "1":
                                    Point = "1#隔条仓";
                                    break;
                                case "2":
                                    Point = "2#隔条仓";
                                    break;
                                case "3":
                                    Point = "1#堆垛位";
                                    break;
                                case "4":
                                    Point = "2#堆垛位";
                                    break;
                                case "5":
                                    Point = "底部隔条仓";
                                    break;
                                case "6":
                                    Point = "隔条总仓";
                                    break;
                                case "7":
                                    Point = "1#均质炉";
                                    break;
                                case "8":
                                    Point = "2#均质炉";
                                    break;
                                case "9":
                                    Point = "1#冷却室";
                                    break;
                                case "10":
                                    Point = "3#均质炉";
                                    break;
                                case "11":
                                    Point = "4#均质炉";
                                    break;
                                case "12":
                                    Point = "2#冷却室";
                                    break;
                                case "13":
                                    Point = "1#解垛位";
                                    break;
                                case "14":
                                    Point = "2#解垛位";
                                    break;
                                case "15":
                                    Point = "3#解垛位";
                                    break;
                                case "16":
                                    Point = "3#隔条仓";
                                    break;
                                default:
                                    break;
                            }
                            if (CurrentStartPoint != Point)
                            {
                                CurrentStartPoint = Point;
                                Messenger.Default.Send<NotificationMessage<string>>(new NotificationMessage<string>(Point, "ExecAnimation"));
                                Thread.Sleep(5000);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    LogTool.SaveSysLog(e.Message, "加料车状态监控、动画移动、控制模式显隐异常");
                }
            }
        }
        /// <summary>
        /// 控制面板控件显隐1.6#线程的方法
        /// </summary>
        private void ListeningExplicitAndImplicitControlMode()
        {
            while (true)
            {
                try
                {
                    if (IsReadingPlc && ListeningAllTagQueue.Count > 0 && IsOnLine)
                    {
                        TagInfo tagInfo2 = GetTagInfoByTagDesc("自动控制使能");
                        if (tagInfo2.Value == "True")
                        {
                            if (LED2NotLight != Visibility.Hidden)
                            {
                                Thread.Sleep(10);
                                Application.Current.Dispatcher.Invoke((Action)delegate ()
                                {
                                    LED2NotLight = Visibility.Hidden;
                                });
                            }
                            if (LED2Light != Visibility.Visible)
                            {
                                Thread.Sleep(10);
                                Application.Current.Dispatcher.Invoke((Action)delegate ()
                                {
                                    LED2Light = Visibility.Visible;//LED灯2亮
                                });
                            }
                        }
                        else if (tagInfo2.Value == "False")
                        {
                            if (LED2NotLight != Visibility.Visible)
                            {
                                Thread.Sleep(10);
                                Application.Current.Dispatcher.Invoke((Action)delegate ()
                                {
                                    LED2NotLight = Visibility.Visible;//LED灯2灭
                                    IsRemoteControl();
                                });
                            }
                            if (LED2Light != Visibility.Hidden)
                            {
                                Thread.Sleep(10);
                                Application.Current.Dispatcher.Invoke((Action)delegate ()
                                {
                                    LED2Light = Visibility.Hidden;
                                });
                            }
                            if (ReadPlcStatus1 != Visibility.Hidden)
                            {
                                Thread.Sleep(10);
                                Application.Current.Dispatcher.Invoke((Action)delegate ()
                                {
                                    ReadPlcStatus1 = Visibility.Hidden;//隐藏启动监控按钮
                                });
                            }
                            if (ReadPlcStatus2 != Visibility.Visible)
                            {
                                Thread.Sleep(10);
                                Application.Current.Dispatcher.Invoke((Action)delegate ()
                                {
                                    ReadPlcStatus2 = Visibility.Visible;//显示停止监控按钮
                                });
                            }
                            if (ShowAutomaticButton != Visibility.Visible)
                            {
                                Thread.Sleep(10);
                                Application.Current.Dispatcher.Invoke((Action)delegate ()
                                {
                                    ShowAutomaticButton = Visibility.Visible;//显示自动控制按钮
                                });
                            }
                        }


                    }
                    Thread.Sleep(1000);
                }
                catch (Exception e)
                {
                    LogTool.SaveSysLog(e.Message, "控制面板控件显隐异常");
                }
            }
        }
        /// <summary>
        /// 加料车1.7#线程 灯显隐
        /// </summary>
        private void ListeningFeedingTruckControlLight()
        {
            while (true)
            {
                try
                {
                    if (IsReadingPlc && ListeningAllTagQueue.Count > 0 && IsOnLine)
                    {
                        TagInfo tag1 = GetTagInfoByTagDesc("加料车待命");
                        if (tag1.Value == "False") //1不工作，0是工作
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                FeedingTruckWorkingVisibility = Visibility.Visible;
                                FeedingTruckNoWorkingVisibility = Visibility.Hidden;
                            });
                        }
                        else if (tag1.Value == "True")
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                FeedingTruckWorkingVisibility = Visibility.Hidden;
                                FeedingTruckNoWorkingVisibility = Visibility.Visible;
                            });
                        }

                        //cx于1月7日屏蔽，显示加料车工作状态灯的信号改为标签：加料车待命
                        //控制加料车工作灯显隐
                        //int AllTaskTagFlasCount = 0;
                        //for (int i = 0; i < ListeningAllTagQueue.Count; i++)
                        //{
                        //    if (ListeningAllTagQueue[i].Type == 2 && ListeningAllTagQueue[i].Value == "True")
                        //    {
                        //        AllTaskTagIsFalse = false;
                        //        AllTaskTagFlasCount++;
                        //    }
                        //}
                        //if (AllTaskTagFlasCount == 0)
                        //{
                        //    AllTaskTagIsFalse = true;
                        //}
                        //if (!AllTaskTagIsFalse)
                        //{
                        //    Thread.Sleep(10);
                        //    Application.Current.Dispatcher.Invoke((Action)delegate ()
                        //    {
                        //        FeedingTruckWorkingVisibility = Visibility.Visible;
                        //        FeedingTruckNoWorkingVisibility = Visibility.Hidden;
                        //    });
                        //}
                        //else
                        //{
                        //    Thread.Sleep(10);
                        //    Application.Current.Dispatcher.Invoke((Action)delegate ()
                        //    {
                        //        FeedingTruckWorkingVisibility = Visibility.Hidden;
                        //        FeedingTruckNoWorkingVisibility = Visibility.Visible;
                        //    });
                        //}


                        //根据加料车急停标签的值，控制急停按钮显隐
                        TagInfo tag = GetTagInfoByTagDesc("加料车急停");
                        if (tag.Value == "False") //0是未停止状态，显示急停按钮
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                Stop = Visibility.Visible;
                                Stoping = Visibility.Hidden;
                            });
                        }
                        else if (tag.Value == "True")//1是停止状态，显示急停中按钮
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                Stop = Visibility.Hidden;
                                Stoping = Visibility.Visible;
                            });
                        }
                        else
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                Stop = Visibility.Hidden;
                                Stoping = Visibility.Hidden;
                            });
                        }
                    }

                    Thread.Sleep(2000);
                }
                catch (Exception e)
                {
                    LogTool.SaveSysLog(e.Message, "加料车灯显隐异常");
                }
            }
        }
        /// <summary>
        /// 设备颜色控制显示方法
        /// </summary>
        private void ListeningEquipmentColorStatus()
        {
            while (true)
            {
                if (IsReadingPlc && ListeningAllTagQueue.Count > 0 && IsOnLine)
                {
                    //根据监控值反馈设备的运行状态
                    MonitorStatusColor();
                }
                Thread.Sleep(500);
            }
        }
        /// <summary>
        /// 算法条件生成
        /// </summary>
        private void AlgorithmConditionGeneration()
        {
            while (true)
            {
                try
                {
                    if (IsReadingPlc && ListeningAllTagQueue.Count > 0 && IsOnLine)
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            if (connectPlc.IsSuccess)
                            {
                                #region 将标签值写入监控标签枚举类中，再写入算法标签枚举类中
                                TagInfo tagInfo = GetTagInfoByTagDesc("1#冷却室冷却完成");
                                if (EquipmentProgramBlockEnum.CoolingChamberNo1Completed == null || EquipmentProgramBlockEnum.CoolingChamberNo1Completed.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.CoolingChamberNo1Completed = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("1#冷却室有料");
                                if (EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium == null || EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("2#冷却室冷却完成");
                                if (EquipmentProgramBlockEnum.CoolingChamberNo2Completed == null || EquipmentProgramBlockEnum.CoolingChamberNo2Completed.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.CoolingChamberNo2Completed = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("2#冷却室有料");
                                if (EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium == null || EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("1#均质炉加热完成");
                                if (EquipmentProgramBlockEnum.HeatingNo1Completed == null || EquipmentProgramBlockEnum.HeatingNo1Completed.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.HeatingNo1Completed = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("1#均质炉有料");
                                if (EquipmentProgramBlockEnum.HeatingNo1HaveAluminium == null || EquipmentProgramBlockEnum.HeatingNo1HaveAluminium.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.HeatingNo1HaveAluminium = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("2#均质炉加热完成");
                                if (EquipmentProgramBlockEnum.HeatingNo2Completed == null || EquipmentProgramBlockEnum.HeatingNo2Completed.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.HeatingNo2Completed = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("2#均质炉有料");
                                if (EquipmentProgramBlockEnum.HeatingNo2HaveAluminium == null || EquipmentProgramBlockEnum.HeatingNo2HaveAluminium.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.HeatingNo2HaveAluminium = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("3#均质炉加热完成");
                                if (EquipmentProgramBlockEnum.HeatingNo3Completed == null || EquipmentProgramBlockEnum.HeatingNo3Completed.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.HeatingNo3Completed = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("3#均质炉有料");
                                if (EquipmentProgramBlockEnum.HeatingNo3HaveAluminium == null || EquipmentProgramBlockEnum.HeatingNo3HaveAluminium.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.HeatingNo3HaveAluminium = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("4#均质炉加热完成");
                                if (EquipmentProgramBlockEnum.HeatingNo4Completed == null || EquipmentProgramBlockEnum.HeatingNo4Completed.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.HeatingNo4Completed = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("4#均质炉有料");
                                if (EquipmentProgramBlockEnum.HeatingNo4HaveAluminium == null || EquipmentProgramBlockEnum.HeatingNo4HaveAluminium.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.HeatingNo4HaveAluminium = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("1#堆垛位满");
                                if (EquipmentProgramBlockEnum.StackingPositionNo1Full == null || EquipmentProgramBlockEnum.StackingPositionNo1Full.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.StackingPositionNo1Full = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("2#堆垛位满");
                                if (EquipmentProgramBlockEnum.StackingPositionNo2Full == null || EquipmentProgramBlockEnum.StackingPositionNo2Full.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.StackingPositionNo2Full = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("隔条总仓空");
                                if (EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty == null || EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("隔条总仓隔条层数");
                                if (EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseLevelNum == null || EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseLevelNum.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseLevelNum = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("1#解垛位空垛");
                                if (EquipmentProgramBlockEnum.DestackingNo1Empty == null || EquipmentProgramBlockEnum.DestackingNo1Empty.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.DestackingNo1Empty = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("1#解垛位仅剩隔条");
                                if (EquipmentProgramBlockEnum.DestackingNo1OnlySpacerStrip == null || EquipmentProgramBlockEnum.DestackingNo1OnlySpacerStrip.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.DestackingNo1OnlySpacerStrip = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("2#解垛位空垛");
                                if (EquipmentProgramBlockEnum.DestackingNo2Empty == null || EquipmentProgramBlockEnum.DestackingNo2Empty.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.DestackingNo2Empty = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("2#解垛位仅剩隔条");
                                if (EquipmentProgramBlockEnum.DestackingNo2OnlySpacerStrip == null || EquipmentProgramBlockEnum.DestackingNo2OnlySpacerStrip.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.DestackingNo2OnlySpacerStrip = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("3#解垛位空垛");
                                if (EquipmentProgramBlockEnum.DestackingNo3Empty == null || EquipmentProgramBlockEnum.DestackingNo3Empty.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.DestackingNo3Empty = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("3#解垛位仅剩隔条");
                                if (EquipmentProgramBlockEnum.DestackingNo3OnlySpacerStrip == null || EquipmentProgramBlockEnum.DestackingNo3OnlySpacerStrip.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.DestackingNo3OnlySpacerStrip = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("3#隔条仓满");
                                if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Full == null || EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Full.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Full = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("3#隔条仓空");
                                if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Empty == null || EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Empty.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Empty = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("3#隔条仓层数");
                                if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo3LevelNum == null || EquipmentProgramBlockEnum.SpacerStripWarehouseNo3LevelNum.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3LevelNum = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("1#隔条仓层数");
                                if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero == null || EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("1#隔条仓为空");
                                if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo1Empty == null || EquipmentProgramBlockEnum.SpacerStripWarehouseNo1Empty.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo1Empty = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("2#隔条仓层数");
                                if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo2LevelIsZero == null || EquipmentProgramBlockEnum.SpacerStripWarehouseNo2LevelIsZero.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo2LevelIsZero = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("2#隔条仓为空");
                                if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo2Empty == null || EquipmentProgramBlockEnum.SpacerStripWarehouseNo2Empty.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo2Empty = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("1#堆垛位满");
                                if (EquipmentProgramBlockEnum.StackingPositionNo1Full == null || EquipmentProgramBlockEnum.StackingPositionNo1Full.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.StackingPositionNo1Full = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("1#铝垛堆叠层数");
                                if (EquipmentProgramBlockEnum.StackingPositionNo1LevelNum == null || EquipmentProgramBlockEnum.StackingPositionNo1LevelNum.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.StackingPositionNo1LevelNum = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("2#堆垛位满");
                                if (EquipmentProgramBlockEnum.StackingPositionNo2Full == null || EquipmentProgramBlockEnum.StackingPositionNo2Full.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.StackingPositionNo2Full = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("2#铝垛堆叠层数");
                                if (EquipmentProgramBlockEnum.StackingPositionNo2LevelNum == null || EquipmentProgramBlockEnum.StackingPositionNo2LevelNum.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.StackingPositionNo2LevelNum = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("自动控制使能");
                                if (EquipmentProgramBlockEnum.MonitorModel == null || EquipmentProgramBlockEnum.MonitorModel.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.MonitorModel = tagInfo;
                                }
                                tagInfo = GetTagInfoByTagDesc("解垛位送料许可");
                                if (EquipmentProgramBlockEnum.Allow == null || EquipmentProgramBlockEnum.Allow.Value != tagInfo.Value)
                                {
                                    EquipmentProgramBlockEnum.Allow = tagInfo;
                                }
                            }
                            #endregion 将标签值写入监控标签队列中
                        });
                    }
                    Thread.Sleep(500);
                }
                catch (Exception e)
                {
                    LogTool.SaveSysLog(e.Message, "算法条件生成异常");
                }
            }
        }
        /// <summary>
        /// 根据监控值反馈设备的运行状态
        /// </summary>
        private void MonitorStatusColor()
        {
            try
            {
                #region 1号冷却室
                //1#冷却室刚冷却完成且有料
                if (EquipmentProgramBlockEnum.CoolingChamberNo1Completed != null &&
                    EquipmentProgramBlockEnum.CoolingChamberNo1Completed.Value == "True" &&
                    !IsLock("冷却室1#"))
                {
                    if (CoolingRoom1Color != StatusColor.TriggeredAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            CoolingRoom1Color = StatusColor.TriggeredAlgorithmFull();
                        });
                    }
                }
                //1#冷却室冷却未完成 
                else if (EquipmentProgramBlockEnum.CoolingChamberNo1Completed != null &&
                    EquipmentProgramBlockEnum.CoolingChamberNo1Completed.Value == "False" &&
                    !IsLock("冷却室1#"))
                {
                    //有料
                    if (EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium != null &&
                        EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium.Value == "True" &&
                        !IsLock("冷却室1#"))
                    {
                        if (CoolingRoom1Color != StatusColor.NoAlgorithmFull())
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                CoolingRoom1Color = StatusColor.NoAlgorithmFull();
                            });
                        }
                    }

                    //无料
                    else if (EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium != null &&
                        EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium.Value == "False" &&
                        !IsLock("冷却室1#"))
                    {
                        if (CoolingRoom1Color != StatusColor.NoAlgorithmEmpty())
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                CoolingRoom1Color = StatusColor.NoAlgorithmEmpty();
                            });
                        }
                    }
                }
                #endregion

                #region 2号冷却室
                //2#冷却室刚冷却完成且有料
                if (EquipmentProgramBlockEnum.CoolingChamberNo2Completed != null &&
                    (EquipmentProgramBlockEnum.CoolingChamberNo2Completed.Value == "True") &&
                    !IsLock("冷却室2#"))
                {
                    if (CoolingRoom2Color != StatusColor.TriggeredAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            CoolingRoom2Color = StatusColor.TriggeredAlgorithmFull();
                        });
                    }
                }
                //2#冷却室冷却未完成
                else if (EquipmentProgramBlockEnum.CoolingChamberNo2Completed != null &&
                    (EquipmentProgramBlockEnum.CoolingChamberNo2Completed.Value == "False") &&
                    !IsLock("冷却室2#"))
                {
                    //有料
                    if (EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium != null && EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium.Value == "True")
                    {
                        if (CoolingRoom2Color != StatusColor.NoAlgorithmFull())
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                CoolingRoom2Color = StatusColor.NoAlgorithmFull();
                            });
                        }
                    }
                    //无料
                    else if (EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium != null && EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium.Value == "False")
                    {
                        if (CoolingRoom2Color != StatusColor.NoAlgorithmEmpty())
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                CoolingRoom2Color = StatusColor.NoAlgorithmEmpty();
                            });
                        }
                    }
                }
                #endregion

                #region 1#均质炉
                //1#均质炉刚加热完成且有料
                if (EquipmentProgramBlockEnum.HeatingNo1Completed != null &&
                    EquipmentProgramBlockEnum.HeatingNo1Completed.Value == "True" &&
                    !IsLock("均质炉1#"))
                {
                    if (Heating1Color != StatusColor.TriggeredAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            Heating1Color = StatusColor.TriggeredAlgorithmFull();
                        });
                    }
                }
                //1#均质炉加热未完成
                else if (EquipmentProgramBlockEnum.HeatingNo1Completed != null &&
                    EquipmentProgramBlockEnum.HeatingNo1Completed.Value == "False" &&
                    !IsLock("均质炉1#"))
                {
                    //有料
                    if (EquipmentProgramBlockEnum.HeatingNo1HaveAluminium != null &&
                        EquipmentProgramBlockEnum.HeatingNo1HaveAluminium.Value == "True")
                    {
                        if (Heating1Color != StatusColor.NoAlgorithmFull())
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                Heating1Color = StatusColor.NoAlgorithmFull();
                            });
                        }
                    }
                    //无料
                    else if (EquipmentProgramBlockEnum.HeatingNo1HaveAluminium != null && EquipmentProgramBlockEnum.HeatingNo1HaveAluminium.Value == "False")
                    {
                        if (Heating1Color != StatusColor.NoAlgorithmEmpty())
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                Heating1Color = StatusColor.NoAlgorithmEmpty();
                            });
                        }
                    }
                }
                #endregion

                #region 2#均质炉
                //2#均质炉刚加热完成且有料
                if (EquipmentProgramBlockEnum.HeatingNo2Completed != null &&
                    EquipmentProgramBlockEnum.HeatingNo2Completed.Value == "True" &&
                    !IsLock("均质炉2#"))
                {
                    if (Heating2Color != StatusColor.TriggeredAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            Heating2Color = StatusColor.TriggeredAlgorithmFull();
                        });
                    }
                }
                //2#均质炉加热未完成
                else if (EquipmentProgramBlockEnum.HeatingNo2Completed != null &&
                    EquipmentProgramBlockEnum.HeatingNo2Completed.Value == "False" &&
                    !IsLock("均质炉2#"))
                {
                    //有料
                    if (EquipmentProgramBlockEnum.HeatingNo2HaveAluminium != null && EquipmentProgramBlockEnum.HeatingNo2HaveAluminium.Value == "True")
                    {
                        if (Heating2Color != StatusColor.NoAlgorithmFull())
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                Heating2Color = StatusColor.NoAlgorithmFull();
                            });
                        }
                    }
                    //无料
                    else if (EquipmentProgramBlockEnum.HeatingNo2HaveAluminium != null && EquipmentProgramBlockEnum.HeatingNo2HaveAluminium.Value == "False")
                    {
                        if (Heating2Color != StatusColor.NoAlgorithmEmpty())
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                Heating2Color = StatusColor.NoAlgorithmEmpty();
                            });
                        }
                    }
                }
                #endregion

                #region 3#均质炉
                //3#均质炉刚加热完成且有料
                if (EquipmentProgramBlockEnum.HeatingNo3Completed != null &&
                    EquipmentProgramBlockEnum.HeatingNo3Completed.Value == "True" &&
                    !IsLock("均质炉3#"))
                {
                    if (Heating3Color != StatusColor.TriggeredAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            Heating3Color = StatusColor.TriggeredAlgorithmFull();
                        });
                    }
                }
                //3#均质炉加热未完成
                else if (EquipmentProgramBlockEnum.HeatingNo3Completed != null &&
                    EquipmentProgramBlockEnum.HeatingNo3Completed.Value == "False" &&
                    !IsLock("均质炉3#"))
                {
                    //有料
                    if (EquipmentProgramBlockEnum.HeatingNo3HaveAluminium != null &&
                        EquipmentProgramBlockEnum.HeatingNo3HaveAluminium.Value == "True")
                    {
                        if (Heating3Color != StatusColor.NoAlgorithmFull())
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                Heating3Color = StatusColor.NoAlgorithmFull();
                            });
                        }
                    }
                    //无料
                    else if (EquipmentProgramBlockEnum.HeatingNo3HaveAluminium != null && EquipmentProgramBlockEnum.HeatingNo3HaveAluminium.Value == "False")
                    {
                        if (Heating3Color != StatusColor.NoAlgorithmEmpty())
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                Heating3Color = StatusColor.NoAlgorithmEmpty();
                            });
                        }
                    }
                }
                #endregion

                #region 4#均质炉
                //4#均质炉刚加热完成且有料
                if (EquipmentProgramBlockEnum.HeatingNo4Completed != null &&
                    EquipmentProgramBlockEnum.HeatingNo4Completed.Value == "True" &&
                    !IsLock("均质炉4#"))
                {
                    if (Heating4Color != StatusColor.TriggeredAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            Heating4Color = StatusColor.TriggeredAlgorithmFull();
                        });
                    }
                }
                //4#均质炉加热未完成
                else if (EquipmentProgramBlockEnum.HeatingNo4Completed != null &&
                    EquipmentProgramBlockEnum.HeatingNo4Completed.Value == "False" &&
                    !IsLock("均质炉4#"))
                {
                    //有料
                    if (EquipmentProgramBlockEnum.HeatingNo4HaveAluminium != null &&
                        EquipmentProgramBlockEnum.HeatingNo4HaveAluminium.Value == "True")
                    {
                        if (Heating4Color != StatusColor.NoAlgorithmFull())
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                Heating4Color = StatusColor.NoAlgorithmFull();
                            });
                        }
                    }
                    //无料
                    else if (EquipmentProgramBlockEnum.HeatingNo4HaveAluminium != null && EquipmentProgramBlockEnum.HeatingNo4HaveAluminium.Value == "False")
                    {
                        if (Heating4Color != StatusColor.NoAlgorithmEmpty())
                        {
                            Thread.Sleep(10);
                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                            {
                                Heating4Color = StatusColor.NoAlgorithmEmpty();
                            });
                        }
                    }
                }
                #endregion

                #region 1#堆垛位
                //1#堆垛位满
                if (EquipmentProgramBlockEnum.StackingPositionNo1Full != null &&
                    EquipmentProgramBlockEnum.StackingPositionNo1Full.Value == "True" &&
                    !IsLock("堆垛位1#"))
                {
                    if (StackingPositionNo1Color != StatusColor.TriggeredAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            StackingPositionNo1Color = StatusColor.TriggeredAlgorithmFull();
                        });
                    }
                }
                //1#堆垛位有料
                else if (EquipmentProgramBlockEnum.StackingPositionNo1Full != null &&
                    EquipmentProgramBlockEnum.StackingPositionNo1Full.Value == "False" &&
                    EquipmentProgramBlockEnum.StackingPositionNo1LevelNum != null &&
                    EquipmentProgramBlockEnum.StackingPositionNo1LevelNum.Value != null &&
                    int.Parse(EquipmentProgramBlockEnum.StackingPositionNo1LevelNum.Value) > 0 &&
                    !IsLock("堆垛位1#"))
                {
                    if (StackingPositionNo1Color != StatusColor.NoAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            StackingPositionNo1Color = StatusColor.NoAlgorithmFull();
                        });
                    }
                }
                //1#堆垛位无料
                else if (EquipmentProgramBlockEnum.StackingPositionNo1Full != null &&
                    EquipmentProgramBlockEnum.StackingPositionNo1Full.Value == "False" &&
                    EquipmentProgramBlockEnum.StackingPositionNo1LevelNum != null &&
                    EquipmentProgramBlockEnum.StackingPositionNo1LevelNum.Value != null &&
                    int.Parse(EquipmentProgramBlockEnum.StackingPositionNo1LevelNum.Value) == 0 &&
                    !IsLock("堆垛位1#"))
                {
                    if (StackingPositionNo1Color != StatusColor.NoAlgorithmEmpty())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            StackingPositionNo1Color = StatusColor.NoAlgorithmEmpty();
                        });
                    }
                }
                #endregion

                #region 2#堆垛位
                //2#堆垛位满
                if (EquipmentProgramBlockEnum.StackingPositionNo2Full != null &&
                    EquipmentProgramBlockEnum.StackingPositionNo2Full.Value == "True" &&
                    !IsLock("堆垛位2#"))
                {
                    if (StackingPositionNo2Color != StatusColor.TriggeredAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            StackingPositionNo2Color = StatusColor.TriggeredAlgorithmFull();
                        });
                    }
                }
                //2#堆垛位有料
                else if (EquipmentProgramBlockEnum.StackingPositionNo2Full != null &&
                    EquipmentProgramBlockEnum.StackingPositionNo2Full.Value == "False" &&
                    EquipmentProgramBlockEnum.StackingPositionNo2LevelNum != null &&
                    EquipmentProgramBlockEnum.StackingPositionNo2LevelNum.Value != null &&
                    int.Parse(EquipmentProgramBlockEnum.StackingPositionNo2LevelNum.Value) > 0 &&
                    !IsLock("堆垛位2#"))
                {
                    if (StackingPositionNo2Color != StatusColor.NoAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            StackingPositionNo2Color = StatusColor.NoAlgorithmFull();
                        });
                    }
                }
                //2#堆垛位无料
                else if (EquipmentProgramBlockEnum.StackingPositionNo2Full != null &&
                    EquipmentProgramBlockEnum.StackingPositionNo2Full.Value == "False" &&
                    EquipmentProgramBlockEnum.StackingPositionNo2LevelNum != null &&
                    EquipmentProgramBlockEnum.StackingPositionNo2LevelNum.Value != null &&
                    int.Parse(EquipmentProgramBlockEnum.StackingPositionNo2LevelNum.Value) == 0 &&
                    !IsLock("堆垛位2#"))
                {
                    if (StackingPositionNo2Color != StatusColor.NoAlgorithmEmpty())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            StackingPositionNo2Color = StatusColor.NoAlgorithmEmpty();
                        });
                    }
                }
                #endregion

                #region 1#隔条仓
                //1#隔条仓层数为0
                if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero != null &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero.Value != null &&
                    int.Parse(EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero.Value) == 0 &&
                    !IsLock("隔条仓1#")
                    )
                {
                    if (SpacerStripWarehouse1Color != StatusColor.NoAlgorithmEmpty())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            SpacerStripWarehouse1Color = StatusColor.NoAlgorithmEmpty();
                        });
                    }
                }
                //1#隔条仓层数不为0
                else if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero != null &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero.Value != null &&
                    int.Parse(EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero.Value) > 0 &&
                    !IsLock("隔条仓1#"))
                {
                    if (SpacerStripWarehouse1Color != StatusColor.NoAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            SpacerStripWarehouse1Color = StatusColor.NoAlgorithmFull();
                        });
                    }
                }
                #endregion

                #region 2#隔条仓
                //2#隔条仓层数为0
                if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo2LevelIsZero != null &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo2LevelIsZero.Value != null &&
                    int.Parse(EquipmentProgramBlockEnum.SpacerStripWarehouseNo2LevelIsZero.Value) == 0 &&
                    !IsLock("隔条仓2#"))
                {
                    if (SpacerStripWarehouse2Color != StatusColor.NoAlgorithmEmpty())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            SpacerStripWarehouse2Color = StatusColor.NoAlgorithmEmpty();
                        });
                    }
                }
                //2#隔条仓层数不为0
                else if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo2LevelIsZero != null &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo2LevelIsZero.Value != null &&
                    int.Parse(EquipmentProgramBlockEnum.SpacerStripWarehouseNo2LevelIsZero.Value) > 0 &&
                    !IsLock("隔条仓2#"))
                {
                    if (SpacerStripWarehouse2Color != StatusColor.NoAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            SpacerStripWarehouse2Color = StatusColor.NoAlgorithmFull();
                        });
                    }
                }
                #endregion

                #region 隔条总仓
                //隔条总仓空
                if (EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty != null &&
                    EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty.Value == "True" &&
                    !IsLock("隔条总仓"))
                {
                    if (SpacerStripGeneralWarehouseColor != StatusColor.NoAlgorithmEmpty())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            SpacerStripGeneralWarehouseColor = StatusColor.NoAlgorithmEmpty();
                        });
                    }
                }
                //隔条总仓有料
                else if (EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty != null &&
                    EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty.Value == "False" &&
                    EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseLevelNum != null &&
                    EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseLevelNum.Value != null &&
                    int.Parse(EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseLevelNum.Value) > 0 &&
                    !IsLock("隔条总仓"))
                {
                    if (SpacerStripGeneralWarehouseColor != StatusColor.NoAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            SpacerStripGeneralWarehouseColor = StatusColor.NoAlgorithmFull();
                        });
                    }
                }
                //隔条总仓无料（有隔条架子）
                else if (EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty != null &&
                    EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty.Value == "False" &&
                    EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseLevelNum != null &&
                    EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseLevelNum.Value != null &&
                    int.Parse(EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseLevelNum.Value) == 0 &&
                    !IsLock("隔条总仓"))
                {
                    if (SpacerStripGeneralWarehouseColor != StatusColor.NoAlgorithmEmpty())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            SpacerStripGeneralWarehouseColor = StatusColor.NoAlgorithmFull();
                        });
                    }
                }
                #endregion

                #region 1#解垛位
                //1#解垛位仅剩隔条
                if (EquipmentProgramBlockEnum.DestackingNo1OnlySpacerStrip != null &&
                    EquipmentProgramBlockEnum.DestackingNo1OnlySpacerStrip.Value == "True" &&
                    !IsLock("解垛位1#"))
                {
                    if (DestackingNo1Color != StatusColor.TriggeredAlgorithmEmpty())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            DestackingNo1Color = StatusColor.TriggeredAlgorithmEmpty();
                        });
                    }
                }
                //1#解垛位有料
                else if (EquipmentProgramBlockEnum.DestackingNo1OnlySpacerStrip != null &&
                    EquipmentProgramBlockEnum.DestackingNo1OnlySpacerStrip.Value == "False" &&
                    EquipmentProgramBlockEnum.DestackingNo1Empty.Value == "False" &&
                    !IsLock("解垛位1#"))
                {
                    if (DestackingNo1Color != StatusColor.NoAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            DestackingNo1Color = StatusColor.NoAlgorithmFull();
                        });
                    }
                }
                //1#解垛位无料（没有隔条）
                else if (EquipmentProgramBlockEnum.DestackingNo1OnlySpacerStrip != null &&
                    EquipmentProgramBlockEnum.DestackingNo1OnlySpacerStrip.Value == "False" &&
                    EquipmentProgramBlockEnum.DestackingNo1Empty.Value == "True" &&
                    !IsLock("解垛位1#"))
                {
                    if (DestackingNo1Color != StatusColor.NoAlgorithmEmpty())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            DestackingNo1Color = StatusColor.NoAlgorithmEmpty();
                        });
                    }
                }
                #endregion

                #region 2#解垛位
                //2#解垛位仅剩隔条
                if (EquipmentProgramBlockEnum.DestackingNo2OnlySpacerStrip != null &&
                    EquipmentProgramBlockEnum.DestackingNo2OnlySpacerStrip.Value == "True" &&
                    !IsLock("解垛位2#"))
                {
                    if (DestackingNo2Color != StatusColor.TriggeredAlgorithmEmpty())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            DestackingNo2Color = StatusColor.TriggeredAlgorithmEmpty();
                        });
                    }
                }
                //2#解垛位有料
                else if (EquipmentProgramBlockEnum.DestackingNo2OnlySpacerStrip != null &&
                    EquipmentProgramBlockEnum.DestackingNo2OnlySpacerStrip.Value == "False" &&
                    EquipmentProgramBlockEnum.DestackingNo2Empty.Value == "False" &&
                    !IsLock("解垛位2#"))
                {
                    if (DestackingNo2Color != StatusColor.NoAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            DestackingNo2Color = StatusColor.NoAlgorithmFull();
                        });
                    }
                }
                //2#解垛位无料（没有隔条）
                else if (EquipmentProgramBlockEnum.DestackingNo2OnlySpacerStrip != null &&
                    EquipmentProgramBlockEnum.DestackingNo2OnlySpacerStrip.Value == "False" &&
                    EquipmentProgramBlockEnum.DestackingNo2Empty.Value == "True" &&
                    !IsLock("解垛位2#"))
                {
                    if (DestackingNo2Color != StatusColor.NoAlgorithmEmpty())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            DestackingNo2Color = StatusColor.NoAlgorithmEmpty();
                        });
                    }
                }
                #endregion 2#解垛位

                #region 3#解垛位
                //3#解垛位仅剩隔条
                if (EquipmentProgramBlockEnum.DestackingNo3OnlySpacerStrip != null &&
                    EquipmentProgramBlockEnum.DestackingNo3OnlySpacerStrip.Value == "True" &&
                    !IsLock("解垛位3#"))
                {
                    if (DestackingNo3Color != StatusColor.TriggeredAlgorithmEmpty())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            DestackingNo3Color = StatusColor.TriggeredAlgorithmEmpty();
                        });
                    }
                }
                //3#解垛位有料
                else if (EquipmentProgramBlockEnum.DestackingNo3OnlySpacerStrip != null &&
                    EquipmentProgramBlockEnum.DestackingNo3OnlySpacerStrip.Value == "False" &&
                    EquipmentProgramBlockEnum.DestackingNo3Empty.Value == "False" &&
                    !IsLock("解垛位3#"))
                {
                    if (DestackingNo3Color != StatusColor.NoAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            DestackingNo3Color = StatusColor.NoAlgorithmFull();
                        });
                    }
                }
                //3#解垛位无料（没有隔条）
                else if (EquipmentProgramBlockEnum.DestackingNo3OnlySpacerStrip != null &&
                    EquipmentProgramBlockEnum.DestackingNo3OnlySpacerStrip.Value == "False" &&
                    EquipmentProgramBlockEnum.DestackingNo3Empty.Value == "True" &&
                    !IsLock("解垛位3#"))
                {
                    if (DestackingNo3Color != StatusColor.NoAlgorithmEmpty())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            DestackingNo3Color = StatusColor.NoAlgorithmEmpty();
                        });
                    }
                }
                #endregion

                #region 3#隔条仓
                //3#隔条仓满（隔条满）
                if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Full != null &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Full.Value == "True" &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Empty != null &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Empty.Value == "False" &&
                    !IsLock("隔条仓3#"))
                {
                    if (SpacerStripWarehouseNo3Color != StatusColor.TriggeredAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            SpacerStripWarehouseNo3Color = StatusColor.TriggeredAlgorithmFull();
                        });
                    }
                }
                //3#隔条仓有料（有隔条）
                else if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Full != null &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Full.Value == "False" &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Empty != null &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Empty.Value == "False" &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3LevelNum != null &&
                   EquipmentProgramBlockEnum.SpacerStripWarehouseNo3LevelNum.Value != null &&
                    int.Parse(EquipmentProgramBlockEnum.SpacerStripWarehouseNo3LevelNum.Value) > 0 &&
                    !IsLock("隔条仓3#"))
                {
                    if (SpacerStripWarehouseNo3Color != StatusColor.NoAlgorithmFull())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            SpacerStripWarehouseNo3Color = StatusColor.NoAlgorithmFull();
                        });
                    }
                }
                //3#隔条仓有料（仅有隔条架子）
                else if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Full != null &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Full.Value == "False" &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Empty != null &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Empty.Value == "False" &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3LevelNum.Value != null &&
                    int.Parse(EquipmentProgramBlockEnum.SpacerStripWarehouseNo3LevelNum.Value) == 0 &&
                    !IsLock("隔条仓3#"))
                {
                    if (SpacerStripWarehouseNo3Color != StatusColor.NoAlgorithmEmpty())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            SpacerStripWarehouseNo3Color = StatusColor.NoAlgorithmEmpty();
                        });
                    }
                }
                //3#隔条仓空(无隔条架子)
                else if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Empty != null &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Empty.Value == "True" &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Full != null &&
                    EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Full.Value == "False" &&
                    !IsLock("隔条仓3#"))
                {
                    if (SpacerStripWarehouseNo3Color != StatusColor.TriggeredAlgorithmEmpty())
                    {
                        Thread.Sleep(10);
                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                        {
                            SpacerStripWarehouseNo3Color = StatusColor.TriggeredAlgorithmEmpty();
                        });
                    }
                }
                #endregion
            }
            catch (Exception e)
            {
                LogTool.SaveSysLog(e.Message, "设备颜色反馈状态异常");
            }
        }
        #endregion 1#线程的相关方法

        #region 2#线程的相关方法，2#线程的主要任务是生成任务队列

        /// <summary>
        /// 根据Equip获取是否锁定
        /// </summary>
        /// <param name="Equip"></param>
        /// <returns></returns>
        private bool IsLock(string Equip)
        {
            return DapperTools.Query<LockModel>("select * from Lock where Equip = '" + Equip + "'")[0].LockStatus;
        }

        /// <summary>
        /// 2#线程处理方法，用于依据生成线程的触发条件生成线程。
        /// </summary>
        private void ListeningTask()
        {
            //获取生成算法标签的列表，按优先级进行排序
            ObservableCollection<AlgorithmListModel> PriorityTaskQueue = DapperTools.QueryOc<AlgorithmListModel>(@"select 
                                                                        row_number() over (order by p.Priority,p.PriorityNo) AS PriorityArrangementNumber,
	                                                                    t.Id,
	                                                                    p.Priority,
	                                                                    p.PriorityNo,
	                                                                    p.TagDesc,
	                                                                    t.EquipmentName,
	                                                                    t.Address,
	                                                                    t.ValueType,
	                                                                    t.ReadOrWrite,
	                                                                    t.Remark,
	                                                                    t.IsEnable,
	                                                                    t.Type,
                                                                        t.Point
                                                                    from PriorityConfig p
	                                                                    left join TagInfo t on p.TagDesc = t.TagDesc
                                                                    where IsEnable = 1
                                                                    order by p.Priority,p.PriorityNo
                                                                    ");

            while (true)
            {
                try
                {
                    if (IsAutomatic && !Sortting && IsRemoteControl())
                    {
                        #region 生成任务的算法，将满足条件的任务插入队列
                        foreach (AlgorithmListModel item in PriorityTaskQueue)
                        {
                            switch (item.TagDesc)
                            {
                                case "1#冷却室冷却完成":
                                    if (EquipmentProgramBlockEnum.CoolingChamberNo1Completed != null &&
                                        EquipmentProgramBlockEnum.CoolingChamberNo1Completed.Value == "True"
                                        )
                                    {
                                        //1#解垛位为空，并且起止点不在任务队列中
                                        if (EquipmentProgramBlockEnum.DestackingNo1Empty != null &&
                                            EquipmentProgramBlockEnum.DestackingNo1Empty.Value == "True" &&
                                            EquipmentProgramBlockEnum.Allow.Value == "True" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.DestackingNo1Empty.Point)
                                            )
                                        {
                                            if (!IsLock("冷却室1#") && !IsLock("解垛位1#")) 
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("1#解垛位空垛"), null, GetTagInfoByTagDesc("将1#冷却室的铝料移至1#解垛位"), 1);
                                            }
                                            
                                        }
                                        else if (EquipmentProgramBlockEnum.DestackingNo2Empty != null &&
                                            EquipmentProgramBlockEnum.DestackingNo2Empty.Value == "True" &&
                                            EquipmentProgramBlockEnum.Allow.Value == "True" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.DestackingNo2Empty.Point) 
                                            )
                                        {
                                            if (!IsLock("冷却室1#") && !IsLock("解垛位2#"))
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("2#解垛位空垛"), null, GetTagInfoByTagDesc("将1#冷却室的铝料移至2#解垛位"), 1);
                                            }
                                                
                                        }
                                        else if (EquipmentProgramBlockEnum.DestackingNo3Empty != null &&
                                            EquipmentProgramBlockEnum.DestackingNo3Empty.Value == "True" &&
                                            EquipmentProgramBlockEnum.Allow.Value == "True" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.DestackingNo3Empty.Point) 
                                            )
                                        {
                                            if (!IsLock("冷却室1#") && !IsLock("解垛位3#")) 
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("3#解垛位空垛"), null, GetTagInfoByTagDesc("将1#冷却室的铝料移至3#解垛位"), 1);
                                            }
                                                
                                        }
                                    }
                                    break;
                                case "2#冷却室冷却完成":
                                    if (EquipmentProgramBlockEnum.CoolingChamberNo2Completed != null &&
                                        EquipmentProgramBlockEnum.CoolingChamberNo2Completed.Value == "True")
                                    {
                                        //1#解垛位为空，并且起止点不在任务队列中
                                        if (EquipmentProgramBlockEnum.DestackingNo1Empty != null &&
                                            EquipmentProgramBlockEnum.DestackingNo1Empty.Value == "True" &&
                                            EquipmentProgramBlockEnum.Allow.Value == "True" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.DestackingNo1Empty.Point)
                                            )
                                        {
                                            if (!IsLock("冷却室2#") && !IsLock("解垛位1#")) 
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("1#解垛位空垛"), null, GetTagInfoByTagDesc("将2#冷却室的铝料移至1#解垛位"), 1);
                                            }
                                                
                                        }
                                        else if (EquipmentProgramBlockEnum.DestackingNo2Empty != null &&
                                            EquipmentProgramBlockEnum.DestackingNo2Empty.Value == "True" &&
                                            EquipmentProgramBlockEnum.Allow.Value == "True" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.DestackingNo2Empty.Point))
                                        {
                                            if (!IsLock("冷却室2#") && !IsLock("解垛位2#")) 
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("2#解垛位空垛"), null, GetTagInfoByTagDesc("将2#冷却室的铝料移至2#解垛位"), 1);
                                            }
                                                
                                        }
                                        else if (EquipmentProgramBlockEnum.DestackingNo3Empty != null &&
                                            EquipmentProgramBlockEnum.DestackingNo3Empty.Value == "True" &&
                                            EquipmentProgramBlockEnum.Allow.Value == "True" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.DestackingNo3Empty.Point))
                                        {
                                            if (!IsLock("冷却室2#") && !IsLock("解垛位3#")) 
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("3#解垛位空垛"), null, GetTagInfoByTagDesc("将2#冷却室的铝料移至3#解垛位"), 1);
                                            }
                                        }
                                    }
                                    break;
                                // 
                                case "1#均质炉加热完成":
                                    if (EquipmentProgramBlockEnum.HeatingNo1Completed != null &&
                                        EquipmentProgramBlockEnum.HeatingNo1Completed.Value == "True"
                                        )
                                    {
                                        if (EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium != null &&
                                            EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium.Value == "False" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium.Point)
                                            )
                                        {
                                            if (!IsLock("均质炉1#") && !IsLock("冷却室1#"))
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("1#冷却室有料"), null, GetTagInfoByTagDesc("将1#均质炉的铝料移至1#冷却室"), 1);
                                            }
                                        }
                                        else if (EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium != null &&
                                            EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium.Value == "False" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium.Point))
                                        {
                                            if (!IsLock("均质炉1#") && !IsLock("冷却室2#"))
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("2#冷却室有料"), null, GetTagInfoByTagDesc("将1#均质炉的铝料移至2#冷却室"), 1);
                                            }
                                        }
                                    }
                                    break;
                                //
                                case "2#均质炉加热完成":
                                    if (EquipmentProgramBlockEnum.HeatingNo2Completed != null &&
                                        EquipmentProgramBlockEnum.HeatingNo2Completed.Value == "True")
                                    {
                                        if (EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium != null &&
                                            EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium.Value == "False" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium.Point))
                                        {
                                            if (!IsLock("均质炉2#") && !IsLock("冷却室1#"))
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("1#冷却室有料"), null, GetTagInfoByTagDesc("将2#均质炉的铝料移至1#冷却室"), 1);
                                            }
                                                
                                        }
                                        else if (EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium != null &&
                                            EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium.Value == "False" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium.Point))
                                        {
                                            if (!IsLock("均质炉2#") && !IsLock("冷却室2#")) 
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("2#冷却室有料"), null, GetTagInfoByTagDesc("将2#均质炉的铝料移至2#冷却室"), 1);
                                            } 
                                        }
                                    }
                                    break;
                                case "3#均质炉加热完成":
                                    if (EquipmentProgramBlockEnum.HeatingNo3Completed != null &&
                                        EquipmentProgramBlockEnum.HeatingNo3Completed.Value == "True")
                                    {
                                        if (EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium != null &&
                                            EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium.Value == "False" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium.Point))
                                        {
                                            if (!IsLock("均质炉3#") && !IsLock("冷却室1#")) 
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("1#冷却室有料"), null, GetTagInfoByTagDesc("将3#均质炉的铝料移至1#冷却室"), 1);
                                            } 
                                        }
                                        else if (EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium != null &&
                                            EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium.Value == "False" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium.Point))
                                        {
                                            if (!IsLock("均质炉3#") && !IsLock("冷却室2#")) 
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("2#冷却室有料"), null, GetTagInfoByTagDesc("将3#均质炉的铝料移至2#冷却室"), 1);
                                            }
                                                
                                        }
                                    }
                                    break;
                                case "4#均质炉加热完成":
                                    if (EquipmentProgramBlockEnum.HeatingNo4Completed != null &&
                                        EquipmentProgramBlockEnum.HeatingNo4Completed.Value == "True")
                                    {
                                        if (EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium != null &&
                                            EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium.Value == "False" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.CoolingChamberNo1HaveAluminium.Point))
                                        {
                                            if (!IsLock("均质炉4#") && !IsLock("冷却室1#"))
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("1#冷却室有料"), null, GetTagInfoByTagDesc("将4#均质炉的铝料移至1#冷却室"), 1);
                                            }
                                                
                                        }
                                        else if (EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium != null &&
                                            EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium.Value == "False" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.CoolingChamberNo2HaveAluminium.Point))
                                        {
                                            if (!IsLock("均质炉4#") && !IsLock("冷却室2#"))
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("2#冷却室有料"), null, GetTagInfoByTagDesc("将4#均质炉的铝料移至2#冷却室"), 1);
                                            }
                                                
                                        }
                                    }
                                    break;
                                case "1#堆垛位满":
                                    if (EquipmentProgramBlockEnum.StackingPositionNo1Full != null &&
                                        EquipmentProgramBlockEnum.StackingPositionNo1Full.Value == "True"
                                        )
                                    {
                                        if (EquipmentProgramBlockEnum.HeatingNo1HaveAluminium != null &&
                                            EquipmentProgramBlockEnum.HeatingNo1HaveAluminium.Value == "False" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.HeatingNo1HaveAluminium.Point)
                                            )
                                        {
                                            if (!IsLock("堆垛位1#") && !IsLock("均质炉1#"))
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("1#均质炉有料"), null, GetTagInfoByTagDesc("将1#堆垛位的铝料移至1#均质炉"), 1);
                                            }
                                        }
                                        else if (EquipmentProgramBlockEnum.HeatingNo2HaveAluminium != null &&
                                            EquipmentProgramBlockEnum.HeatingNo2HaveAluminium.Value == "False" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.HeatingNo2HaveAluminium.Point))
                                        {
                                            if (!IsLock("堆垛位1#") && !IsLock("均质炉2#"))
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("2#均质炉有料"), null, GetTagInfoByTagDesc("将1#堆垛位的铝料移至2#均质炉"), 1);
                                            }
                                        }
                                        else if (EquipmentProgramBlockEnum.HeatingNo3HaveAluminium != null &&
                                            EquipmentProgramBlockEnum.HeatingNo3HaveAluminium.Value == "False" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.HeatingNo3HaveAluminium.Point))
                                        {
                                            if (!IsLock("堆垛位1#") && !IsLock("均质炉3#")) 
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("3#均质炉有料"), null, GetTagInfoByTagDesc("将1#堆垛位的铝料移至3#均质炉"), 1);
                                            }
                                        }
                                        else if (EquipmentProgramBlockEnum.HeatingNo4HaveAluminium != null && EquipmentProgramBlockEnum.HeatingNo4HaveAluminium.Value == "False" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.HeatingNo4HaveAluminium.Point))
                                        {
                                            if (!IsLock("堆垛位1#") && !IsLock("均质炉4#")) 
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("4#均质炉有料"), null, GetTagInfoByTagDesc("将1#堆垛位的铝料移至4#均质炉"), 1);
                                            }
                                        }
                                    }
                                    break;
                                case "2#堆垛位满":
                                    if (EquipmentProgramBlockEnum.StackingPositionNo2Full != null &&
                                        EquipmentProgramBlockEnum.StackingPositionNo2Full.Value == "True" 
                                        )
                                    {
                                        if (EquipmentProgramBlockEnum.HeatingNo1HaveAluminium != null &&
                                            EquipmentProgramBlockEnum.HeatingNo1HaveAluminium.Value == "False" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.HeatingNo1HaveAluminium.Point) 
                                            )
                                        {
                                            if (!IsLock("堆垛位2#") && !IsLock("均质炉1#")) 
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("1#均质炉有料"), null, GetTagInfoByTagDesc("将2#堆垛位的铝料移至1#均质炉"), 1);
                                            }
                                                
                                        }
                                        else if (EquipmentProgramBlockEnum.HeatingNo2HaveAluminium != null &&
                                                 EquipmentProgramBlockEnum.HeatingNo2HaveAluminium.Value == "False" &&
                                                 IsNotExistStartPoint(item.Point) &&
                                                 IsNotExistEndPoint(EquipmentProgramBlockEnum.HeatingNo2HaveAluminium.Point) 
                                                 )
                                        {
                                            if (!IsLock("堆垛位2#") && !IsLock("均质炉2#")) 
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("2#均质炉有料"), null, GetTagInfoByTagDesc("将2#堆垛位的铝料移至2#均质炉"), 1);
                                            }
                                                
                                        }
                                        else if (EquipmentProgramBlockEnum.HeatingNo3HaveAluminium != null &&
                                                 EquipmentProgramBlockEnum.HeatingNo3HaveAluminium.Value == "False" &&
                                                 IsNotExistStartPoint(item.Point) &&
                                                 IsNotExistEndPoint(EquipmentProgramBlockEnum.HeatingNo3HaveAluminium.Point) 
                                                 )
                                        {
                                            if (!IsLock("堆垛位2#") && !IsLock("均质炉3#"))
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("3#均质炉有料"), null, GetTagInfoByTagDesc("将2#堆垛位的铝料移至3#均质炉"), 1);
                                            }
                                            
                                        }
                                        else if (EquipmentProgramBlockEnum.HeatingNo4HaveAluminium != null &&
                                                 EquipmentProgramBlockEnum.HeatingNo4HaveAluminium.Value == "False" &&
                                                 IsNotExistStartPoint(item.Point) &&
                                                 IsNotExistEndPoint(EquipmentProgramBlockEnum.HeatingNo4HaveAluminium.Point)
                                                 )
                                        {
                                            if (!IsLock("堆垛位2#") && !IsLock("均质炉4#")) {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("4#均质炉有料"), null, GetTagInfoByTagDesc("将2#堆垛位的铝料移至4#均质炉"), 1);
                                            }
                                            
                                        }
                                    }
                                    break;
                                case "3#隔条仓满":
                                    if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Full != null &&
                                        EquipmentProgramBlockEnum.SpacerStripWarehouseNo3Full.Value == "True"
                                        )
                                    {
                                        if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero != null &&
                                            EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero.Value == "0" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero.Point) &&
                                            EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty != null &&
                                            EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty.Value == "True")
                                        {
                                            if (!IsLock("隔条仓1#") && !IsLock("隔条总仓") && !IsLock("隔条仓3#"))
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("1#隔条仓层数"), GetTagInfoByTagDesc("隔条总仓空"), GetTagInfoByTagDesc("将1#隔条仓的空隔条架子移至隔条总仓"), 2);
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("1#隔条仓层数"), GetTagInfoByTagDesc("隔条总仓空"), GetTagInfoByTagDesc("将3#隔条仓的隔条移至1#隔条仓"), 2);
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("1#隔条仓层数"), GetTagInfoByTagDesc("隔条总仓空"), GetTagInfoByTagDesc("将隔条总仓的空隔条架子移至3#隔条仓"), 2);
                                            }
                                        }
                                        else if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero != null &&
                                                 EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero.Value == "0" &&
                                                 IsNotExistStartPoint(item.Point) &&
                                                 IsNotExistEndPoint(EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero.Point) &&
                                                 EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty != null &&
                                                 EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty.Value == "True")
                                        {
                                            if (!IsLock("隔条仓2#") && !IsLock("隔条总仓") && !IsLock("隔条仓3#"))
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("2#隔条仓层数"), GetTagInfoByTagDesc("隔条总仓空"), GetTagInfoByTagDesc("将2#隔条仓的空隔条架子移至隔条总仓"), 2);
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("2#隔条仓层数"), GetTagInfoByTagDesc("隔条总仓空"), GetTagInfoByTagDesc("将3#隔条仓的隔条移至2#隔条仓"), 2);
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("2#隔条仓层数"), GetTagInfoByTagDesc("隔条总仓空"), GetTagInfoByTagDesc("将隔条总仓的空隔条架子移至3#隔条仓"), 2);
                                            }
                                        }
                                        //3#隔条仓满，1、2、3解垛位至少一个不为空，隔条总仓为空
                                        else if (EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero != null &&
                                                EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero.Value != "0" &&
                                                EquipmentProgramBlockEnum.SpacerStripWarehouseNo2LevelIsZero.Value != "0" &&
                                                IsNotExistStartPoint(item.Point) &&
                                                IsNotExistEndPoint(EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero.Point) &&
                                                IsNotExistEndPoint(EquipmentProgramBlockEnum.SpacerStripWarehouseNo2LevelIsZero.Point) &&
                                                EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty != null &&
                                                EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty.Value == "True" &&
                                                (EquipmentProgramBlockEnum.DestackingNo1Empty.Value != "True" ||
                                                 EquipmentProgramBlockEnum.DestackingNo2Empty.Value != "True" ||
                                                 EquipmentProgramBlockEnum.DestackingNo3Empty.Value != "True")
                                                )
                                        {
                                            if (int.Parse(EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero.Value) <= int.Parse(EquipmentProgramBlockEnum.SpacerStripWarehouseNo2LevelIsZero.Value) &&
                                                int.Parse(EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero.Value) < 15)

                                            {
                                                if (!IsLock("隔条仓1#") && !IsLock("隔条总仓") && !IsLock("隔条仓3#"))
                                                {
                                                    AddToListeningTaskQueue(item, GetTagInfoByTagDesc("1#隔条仓层数"), GetTagInfoByTagDesc("隔条总仓空"), GetTagInfoByTagDesc("将1#隔条仓的空隔条架子移至隔条总仓"), 2);
                                                    AddToListeningTaskQueue(item, GetTagInfoByTagDesc("1#隔条仓层数"), GetTagInfoByTagDesc("隔条总仓空"), GetTagInfoByTagDesc("将3#隔条仓的隔条移至1#隔条仓"), 2);
                                                    AddToListeningTaskQueue(item, GetTagInfoByTagDesc("1#隔条仓层数"), GetTagInfoByTagDesc("隔条总仓空"), GetTagInfoByTagDesc("将隔条总仓的空隔条架子移至3#隔条仓"), 2);
                                                }
                                            }
                                            else if (int.Parse(EquipmentProgramBlockEnum.SpacerStripWarehouseNo1LevelIsZero.Value) > int.Parse(EquipmentProgramBlockEnum.SpacerStripWarehouseNo2LevelIsZero.Value) &&
                                               int.Parse(EquipmentProgramBlockEnum.SpacerStripWarehouseNo2LevelIsZero.Value) < 15)
                                            {
                                                if (!IsLock("隔条仓2#") && !IsLock("隔条总仓") && !IsLock("隔条仓3#"))
                                                {
                                                    AddToListeningTaskQueue(item, GetTagInfoByTagDesc("2#隔条仓层数"), GetTagInfoByTagDesc("隔条总仓空"), GetTagInfoByTagDesc("将2#隔条仓的空隔条架子移至隔条总仓"), 2);
                                                    AddToListeningTaskQueue(item, GetTagInfoByTagDesc("2#隔条仓层数"), GetTagInfoByTagDesc("隔条总仓空"), GetTagInfoByTagDesc("将3#隔条仓的隔条移至2#隔条仓"), 2);
                                                    AddToListeningTaskQueue(item, GetTagInfoByTagDesc("2#隔条仓层数"), GetTagInfoByTagDesc("隔条总仓空"), GetTagInfoByTagDesc("将隔条总仓的空隔条架子移至3#隔条仓"), 2);
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "1#解垛位仅剩隔条":
                                    if (EquipmentProgramBlockEnum.DestackingNo1OnlySpacerStrip != null &&
                                        EquipmentProgramBlockEnum.DestackingNo1OnlySpacerStrip.Value == "True"
                                        )
                                    {
                                        //隔条总仓空
                                        if (EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty != null &&
                                            EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty.Value == "True" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty.Point) 
                                            )
                                        {
                                            if (!IsLock("解垛位1#") && !IsLock("隔条总仓")) {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("隔条总仓空"), null, GetTagInfoByTagDesc("搬运1#解垛位底部隔条"), 1);
                                            }
                                            
                                        }
                                    }
                                    break;
                                case "2#解垛位仅剩隔条":
                                    if (EquipmentProgramBlockEnum.DestackingNo2OnlySpacerStrip != null &&
                                        EquipmentProgramBlockEnum.DestackingNo2OnlySpacerStrip.Value == "True" 
                                        )
                                    {
                                        //隔条总仓空
                                        if (EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty != null &&
                                            EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty.Value == "True" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty.Point) 
                                            )
                                        {
                                            if (!IsLock("解垛位2#") && !IsLock("隔条总仓")) 
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("隔条总仓空"), null, GetTagInfoByTagDesc("搬运2#解垛位底部隔条"), 1);
                                            }
                                            
                                        }
                                    }
                                    break;
                                case "3#解垛位仅剩隔条":
                                    if (EquipmentProgramBlockEnum.DestackingNo3OnlySpacerStrip != null &&
                                        EquipmentProgramBlockEnum.DestackingNo3OnlySpacerStrip.Value == "True" 
                                        )
                                    {
                                        //隔条总仓空
                                        if (EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty != null &&
                                            EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty.Value == "True" &&
                                            IsNotExistStartPoint(item.Point) &&
                                            IsNotExistEndPoint(EquipmentProgramBlockEnum.SpacerStripGeneralWarehouseEmpty.Point) 
                                            )
                                        {
                                            if (!IsLock("解垛位3#") && !IsLock("隔条总仓"))
                                            {
                                                AddToListeningTaskQueue(item, GetTagInfoByTagDesc("隔条总仓空"), null, GetTagInfoByTagDesc("搬运2#解垛位底部隔条"), 1);
                                            }
                                        }
                                    }
                                    break;
                                default:
                                    break;
                            }
                        }
                        #endregion
                    }
                }
                catch (Exception e)
                {
                    LogTool.SaveSysLog(e.Message, "生成任务时的异常");
                }
                Thread.Sleep(100);

            }
        }

        /// <summary>
        /// 将生成的任务插入任务队列
        /// </summary>
        /// <param name="ListeningTask">触发算法的标签（12个）</param>
        /// <param name="FirstTag">触发算法其他标签的第一个标签</param>
        /// <param name="SecondaryTag">触发算法其他标签的第二个标签</param>
        /// <param name="TaskTag">算法触发任务的标签（27个）</param>
        /// <param name="Level">判断是否有两个标签 1表示只有1个辅助标签，2表示有2个辅助标签</param>
        private void AddToListeningTaskQueue(AlgorithmListModel ListeningTask, TagInfo FirstTag, TagInfo SecondaryTag, TagInfo TaskTag, int Level)
        {
            AlgorithmListModel tasks = new AlgorithmListModel();
            Int64 CurrentOrderNo = -9223372036854775808;
            if (TaskQueue.Count > 0)
            {
                Int64 TempOrderNo = TaskQueue[0].OrderNo;
                for (int i = 0; i < TaskQueue.Count; i++)
                {
                    if (TaskQueue[i].OrderNo > TempOrderNo)
                    {
                        TempOrderNo = TaskQueue[i].OrderNo;
                    }
                }
                CurrentOrderNo = TempOrderNo;
            }
            tasks.OrderNo = CurrentOrderNo + 1;
            tasks.TaskDesc = TaskTag.TagDesc;
            tasks.Status = "等待";
            tasks.CreateTime = DateTime.Now;
            tasks.StartPoint = ListeningTask.Point;
            tasks.EndPoint = FirstTag.Point;
            //获取生成算法标签的列表，按优先级进行排序
            ObservableCollection<AlgorithmListModel> PriorityTaskQueue = DapperTools.QueryOc<AlgorithmListModel>(@"select 
                                                                        row_number() over (order by p.Priority,p.PriorityNo) AS PriorityArrangementNumber,
	                                                                    p.Priority,
	                                                                    p.PriorityNo,
	                                                                    p.TagDesc
                                                                    from PriorityConfig p
                                                                    order by p.Priority,p.PriorityNo
                                                                    ");
            for (int i = 0; i < PriorityTaskQueue.Count; i++)
            {
                if (PriorityTaskQueue[i].TagDesc == ListeningTask.TagDesc)
                {
                    tasks.PriorityArrangementNumber = PriorityTaskQueue[i].PriorityArrangementNumber;
                    break;
                }
            }
            Thread.Sleep(10);
            Application.Current.Dispatcher.Invoke((Action)delegate
            {
                TaskQueue.Add(tasks);
            });
            while (true)
            {
                if (!Deleting)
                {
                    //开始排序，避免排序时被执行
                    Sortting = true;
                    //获取状态为等待的列表数据
                    ObservableCollection<AlgorithmListModel> TempTasks = new ObservableCollection<AlgorithmListModel>();
                    for (int i = 0; i < TaskQueue.Count; i++)
                    {
                        if (TaskQueue[i].Status == "等待")
                        {
                            TempTasks.Add(TaskQueue[i]);
                        }
                    }
                    //对等待的列表进行排序
                    for (int i = 0; i < TempTasks.Count - 1; i++)
                    {
                        for (int j = 0; j < TempTasks.Count - 1 - i; j++)
                        {
                            if (TempTasks[j].PriorityArrangementNumber > TempTasks[j + 1].PriorityArrangementNumber)
                            {
                                AlgorithmListModel temp = TempTasks[j];
                                TempTasks[j] = TempTasks[j + 1];
                                TempTasks[j + 1] = temp;
                            }
                        }
                    }
                    //获取非等待的列表
                    ObservableCollection<AlgorithmListModel> TempTaskQueue = new ObservableCollection<AlgorithmListModel>();
                    for (int i = 0; i < TaskQueue.Count; i++)
                    {
                        if (TaskQueue[i].Status != "等待")
                        {
                            AlgorithmListModel NotWaitTask = TransExpV2<AlgorithmListModel, AlgorithmListModel>.Trans(TaskQueue[i]);
                            TempTaskQueue.Add(NotWaitTask);
                        }
                    }
                    //非等待的列表添加等待的列表
                    for (int i = 0; i < TempTasks.Count; i++)
                    {
                        bool IsNotHave = true;
                        //验证是否包含，避免排序前就被执行，或添加重复任务，因已执行的任务优先级大于等待的任务
                        for (int j = 0; j < TempTaskQueue.Count; j++)
                        {
                            if (TempTasks[i].OrderNo == TempTaskQueue[j].OrderNo)
                            {
                                IsNotHave = false;
                                break;
                            }
                        }
                        //不包含则加入到序列
                        if (IsNotHave)
                        {
                            TempTaskQueue.Add(TempTasks[i]);
                        }
                    }
                    //覆盖当前任务列表
                    Application.Current.Dispatcher.Invoke((Action)delegate
                    {
                        TaskQueue = TempTaskQueue;
                    });
                    //排序结束
                    Sortting = false;
                    break;
                }
                Thread.Sleep(10);
            }
        }


        #region 为防止生成相同任务的验证方法
        /// <summary>
        /// 是否不包含开始点位
        /// </summary>
        private bool IsNotExistStartPoint(string Point)
        {
            if (Sortting || Deleting)
            {
                return false;
            }
            bool result = true;
            for (int i = 0; i < TaskQueue.Count; i++)
            {
                if (TaskQueue[i].Status != "已完成" && TaskQueue[i].StartPoint == Point)
                {
                    result = false;
                }
            }
            return result;
        }
        /// <summary>
        /// 是否不包含终点点位
        /// </summary>
        private bool IsNotExistEndPoint(string Point)
        {
            if (Sortting || Deleting)
            {
                return false;
            }
            bool result = true;
            for (int i = 0; i < TaskQueue.Count; i++)
            {
                if (TaskQueue[i].Status != "已完成" && TaskQueue[i].EndPoint == Point)
                {
                    result = false;
                }
            }
            return result;
        }
        #endregion 为防止生成相同任务的验证方法

        #endregion 2#线程的相关方法

        #region 3#线程的相关方法，3#线程的主要任务是将任务队列的任务下达给PLC，并根据PLC反馈结果更新任务状态
        /// <summary>
        /// 是否远程控制
        /// </summary>
        /// <returns></returns>
        private bool IsRemoteControl()
        {
            TagInfo tag = GetTagInfoByTagDesc("自动控制使能");
            if (tag.Value == "True")
            {
                return true;
            }
            else
            {
                //清空当前任务列表
                //
                if (TaskQueue.Count > 0)
                {
                    Application.Current.Dispatcher.Invoke((Action)delegate
                    {
                        for (int i = 0; i < TaskQueue.Count; i++)
                        {
                            if (TaskQueue[i].Id != 0 && TaskQueue[i].Status != "已完成")
                            {
                                string sql = @"SELECT * FROM TaskInfo WHERE Id = @Id ";
                                TaskInfo whereModel = new TaskInfo
                                {
                                    Id = TaskQueue[i].Id
                                };
                                TaskInfo RemoveAlgorithmListModel = DapperTools.Query(sql, whereModel);
                                //执行sql,更新任务状态
                                sql = @"DELETE TaskInfo WHERE Id = @Id ";
                                _ = DapperTools.Delete(sql, RemoveAlgorithmListModel);
                            }
                        }
                        TaskQueue = new ObservableCollection<AlgorithmListModel>();
                    });
                }
                return false;
            }
        }



        /// <summary>
        /// 3#线程处理方法，执行任务。
        /// </summary>
        private void ExecuteTask()
        {
            while (true)
            {
                try
                {
                    ///1判断加料车在线，2自动控制启动，3任务队列有任务，4没执行排序算法
                    if (IsOnLine && IsAutomatic && TaskQueue.Count > 0 && !Sortting && IsRemoteControl())
                    {
                        AlgorithmListModel FirstTask = GetFirstTaks();
                        if (FirstTask != null && !Sortting && IsRemoteControl())
                        {
                            TagInfo SystemConfirmCompleteTag = GetTagInfoByTagDesc("控制系统确认任务完成");
                            if (TaskQueue.Count > 0 && FirstTask.Status == "等待" && IsNotHaveInProgressTask() && !Sortting && IsRemoteControl())
                            {
                                //1.获取任务对应的程序块，并写入PLC值
                                TagInfo FirstTaskTagInfo = GetTagInfoByTagDesc(FirstTask);
                                //将任务对应标签赋值true
                                FirstTask.Value = "True";
                                //更改任务表
                                FirstTask.StartTime = DateTime.Now;
                                FirstTask.Status = "执行中";
                                TaskInfo DataBaseTaskInfo = new TaskInfo
                                {
                                    TaskDesc = FirstTask.TaskDesc,
                                    StartTime = FirstTask.StartTime,
                                    Status = FirstTask.Status,
                                    CreateTime = FirstTask.CreateTime,
                                    StartPoint = FirstTask.StartPoint,
                                    EndPoint = FirstTask.EndPoint,
                                    OrderNo = FirstTask.OrderNo,
                                    IsDelete = FirstTask.IsDelete
                                };
                                UpdateTaskListForUI(FirstTask);
                                try
                                {
                                    DapperTools.Add<TaskInfo>(@"insert into TaskInfo(
                                                        [TaskDesc]
                                                       ,[CreateTime]
                                                       ,[StartTime]
                                                       ,[StartPoint]
                                                       ,[EndPoint]
                                                       ,[Status]
                                                       ,[OrderNo]
                                                       ,[IsDelete]
                                                        ) VALUES(
                                                        @TaskDesc
                                                       ,@CreateTime
                                                       ,@StartTime
                                                       ,@StartPoint
                                                       ,@EndPoint
                                                       ,@Status
                                                       ,@OrderNo
                                                       ,@IsDelete
)", DataBaseTaskInfo);
                                    DataBaseTaskInfo.Id = DapperTools.Query<TaskInfo>("SELECT MAX(Id) AS Id FROM TaskInfo", new TaskInfo()).Id;
                                    FirstTask.Id = DataBaseTaskInfo.Id;
                                }
                                catch (Exception e)
                                {
                                    LogTool.SaveSysLog(e.Message, "设置任务为执行中异常");
                                }
                                UpdateTaskListForUI(FirstTask);
                                //向PLC下达任务
                                bool WriteResult = WriteSiemensValByAddressAndType(FirstTaskTagInfo.Address, FirstTaskTagInfo.ValueType, "True");
                                if (WriteResult && IsRemoteControl())
                                {
                                    //如果任务已经执行，则监控执行状态反馈
                                    while (true)
                                    {
                                        if (!IsRemoteControl())
                                        {
                                            break;
                                        }
                                        TagInfo SuccessTaskNoTagInfoCondition = new TagInfo();
                                        SuccessTaskNoTagInfoCondition.TagDesc = "执行完成的标签名";
                                        string SuccessTaskNoAddress = DapperTools.Query<TagInfo>("select * from TagInfo WHERE TagDesc = @TagDesc", SuccessTaskNoTagInfoCondition).Address;
                                        string SuccessTaskInfo = siemens.ReadInt32(SuccessTaskNoAddress).Content.ToString();

                                        string SuccessTaskNoAddress1 = DapperTools.Query<TagInfo>("select * from TagInfo WHERE TagDesc = '任务指令执行完成'", SuccessTaskNoTagInfoCondition).Address;
                                        bool SuccessTaskInfo1 = siemens.ReadBool(SuccessTaskNoAddress1).Content;
                                        if (SuccessTaskInfo != null &&
                                            SuccessTaskInfo != "0" &&
                                            SuccessTaskInfo1 == true &&
                                            IsComplete(SuccessTaskInfo, FirstTask) &&
                                            IsRemoteControl()
                                            )
                                        {
                                            DataBaseTaskInfo.EndTime = DateTime.Now;
                                            FirstTask.EndTime = DataBaseTaskInfo.EndTime;
                                            DataBaseTaskInfo.Status = "已完成";
                                            FirstTask.Status = DataBaseTaskInfo.Status;
                                            //当收到PLC执行完成后，控制系统确认完成。
                                            bool ConfirmCompletionWriteResult = WriteSiemensValByAddressAndType(SystemConfirmCompleteTag.Address, SystemConfirmCompleteTag.ValueType, "True");
                                            while (true)
                                            {
                                                if (!ConfirmCompletionWriteResult || !IsRemoteControl())
                                                {
                                                    continue;
                                                }
                                                try
                                                {
                                                    //更改任务表
                                                    int UpdateResult = DapperTools.Update<TaskInfo>(@"update TaskInfo set EndTime = @EndTime,Status = @Status,OrderNo = null WHERE Id = @Id", DataBaseTaskInfo);
                                                }
                                                catch (Exception e)
                                                {
                                                    LogTool.SaveSysLog(e.Message, "设置任务为已完成异常");
                                                }
                                                UpdateTaskListForUI(FirstTask);
                                                while (true)
                                                {
                                                    if (!IsRemoteControl())
                                                    {
                                                        break;
                                                    }
                                                    if (!Sortting)
                                                    {
                                                        //开始删除作业
                                                        Deleting = true;
                                                        //从任务队列中移除任务
                                                        //当等待的任务超过3个的时候从任务队列中移除任务第一个已完成的任务
                                                        List<Int64> CompletedTaskOrderNos = new List<Int64>();
                                                        for (int x = 0; x < TaskQueue.Count; x++)
                                                        {
                                                            if (TaskQueue[x].Status == "已完成")
                                                            {
                                                                CompletedTaskOrderNos.Add(TaskQueue[x].OrderNo);
                                                            }
                                                        }
                                                        if (CompletedTaskOrderNos.Count > 3)
                                                        {
                                                            ObservableCollection<AlgorithmListModel> TempTaskQueue = new ObservableCollection<AlgorithmListModel>();
                                                            for (int i = 0; i < TaskQueue.Count; i++)
                                                            {
                                                                if (CompletedTaskOrderNos[0] != TaskQueue[i].OrderNo)
                                                                {
                                                                    TempTaskQueue.Add(TaskQueue[i]);
                                                                }
                                                            }
                                                            Application.Current.Dispatcher.Invoke((Action)delegate ()
                                                            {
                                                                TaskQueue = TempTaskQueue;
                                                            });
                                                            RaisePropertyChanged("TaskQueue");
                                                        }
                                                        //结束删除作业
                                                        break;
                                                    }
                                                }
                                                break;
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            //正常情况不会执行该程序，但如果切换模式时，可能执行
                            else if (TaskQueue.Count > 0 && FirstTask.Status == "执行中")
                            {
                                //如果任务已经执行，则监控执行状态反馈
                                while (true)
                                {
                                    TagInfo SuccessTaskNoTagInfoCondition = new TagInfo();
                                    SuccessTaskNoTagInfoCondition.TagDesc = "执行完成的标签名";
                                    string SuccessTaskNoAddress = DapperTools.Query<TagInfo>("select * from TagInfo WHERE TagDesc = @TagDesc", SuccessTaskNoTagInfoCondition).Address;
                                    string SuccessTaskInfo = siemens.ReadInt32(SuccessTaskNoAddress).Content.ToString();
                                    if (SuccessTaskInfo != null &&
                                       IsComplete(SuccessTaskInfo, FirstTask) &&
                                       IsRemoteControl())
                                    {
                                        TaskInfo DataBaseTaskInfo = new TaskInfo();
                                        DataBaseTaskInfo.Id = FirstTask.Id;
                                        DataBaseTaskInfo.EndTime = DateTime.Now;
                                        FirstTask.EndTime = DataBaseTaskInfo.EndTime;
                                        DataBaseTaskInfo.Status = "已完成";
                                        FirstTask.Status = "已完成";
                                        //当收到PLC执行完成后，控制系统确认完成。
                                        bool ConfirmCompletionWriteResult = WriteSiemensValByAddressAndType(SystemConfirmCompleteTag.Address, SystemConfirmCompleteTag.ValueType, "True");
                                        while (true)
                                        {
                                            if (!ConfirmCompletionWriteResult || IsRemoteControl())
                                            {
                                                continue;
                                            }
                                            try
                                            {
                                                //更改任务表
                                                int UpdateResult = DapperTools.Update<TaskInfo>(@"update TaskInfo set EndTime = @EndTime,Status = @Status,OrderNo = null WHERE Id = @Id", DataBaseTaskInfo);
                                            }
                                            catch (Exception e)
                                            {
                                                LogTool.SaveSysLog(e.Message, "设置任务为已完成异常");
                                            }
                                            UpdateTaskListForUI(FirstTask);
                                            while (true)
                                            {
                                                if (!IsRemoteControl())
                                                {
                                                    break;
                                                }
                                                if (!Sortting)
                                                {
                                                    //开始删除作业
                                                    Deleting = true;
                                                    //从任务队列中移除任务
                                                    //当等待的任务超过3个的时候从任务队列中移除任务第一个已完成的任务
                                                    List<Int64> CompletedTaskOrderNos = new List<Int64>();
                                                    for (int x = 0; x < TaskQueue.Count; x++)
                                                    {
                                                        if (TaskQueue[x].Status == "已完成")
                                                        {
                                                            CompletedTaskOrderNos.Add(TaskQueue[x].OrderNo);
                                                        }
                                                    }
                                                    if (CompletedTaskOrderNos.Count > 3)
                                                    {
                                                        ObservableCollection<AlgorithmListModel> TempTaskQueue = new ObservableCollection<AlgorithmListModel>();
                                                        for (int i = 0; i < TaskQueue.Count; i++)
                                                        {
                                                            if (CompletedTaskOrderNos[0] != TaskQueue[i].OrderNo)
                                                            {
                                                                TempTaskQueue.Add(TaskQueue[i]);
                                                            }
                                                        }
                                                        Application.Current.Dispatcher.Invoke((Action)delegate ()
                                                        {
                                                            TaskQueue = TempTaskQueue;
                                                        });
                                                        RaisePropertyChanged("TaskQueue");
                                                    }
                                                    //结束删除作业
                                                    Deleting = false;
                                                    break;
                                                }
                                            }
                                            break;
                                        }
                                        break;
                                    }
                                }
                            }

                            ////如果没有任务则叫加料车回归到待机位
                            //else if (TaskQueue.Count == 0)
                            //{
                            //    //加料车回待机位待命
                            //    TagInfo TheChargingTruckReturnsToStandBy = GetTagInfoByTagDesc("加料车回待机位待命");
                            //    //加料车位置
                            //    TagInfo PositionOfChargingTruck = GetTagInfoByTagDesc("加料车位置");
                            //    if (TheChargingTruckReturnsToStandBy.Value == "False" && PositionOfChargingTruck.Value != "9")
                            //    {
                            //        WriteSiemensValByAddressAndType(TheChargingTruckReturnsToStandBy.Address,
                            //            TheChargingTruckReturnsToStandBy.ValueType,
                            //            "True");
                            //    }
                            //}
                        }
                    }
                    Thread.Sleep(10);
                }
                catch (Exception e)
                {
                    LogTool.SaveSysLog(e.Message, "执行任务异常");
                }
            }

        }
        /// <summary>
        /// 根据完成的标签名返回的数据判断完成的任务是否是当前的任务
        /// </summary>
        /// <param name="SuccessTaskInfo">返回的数据</param>
        /// <param name="_FirstTask">当前任务</param>
        /// <returns></returns>
        private bool IsComplete(string SuccessTaskInfo, AlgorithmListModel _FirstTask)
        {
            if (SuccessTaskInfo != null)
            {
                if (GetTaskDesc(int.Parse(SuccessTaskInfo)) == _FirstTask.TaskDesc)
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 删除完成任务线程的方法
        /// </summary>
        private void DeleteCompletedTask()
        {
            while (true)
            {
                try
                {
                    if (IsOnLine && IsAutomatic && TaskQueue.Count > 0 && !Sortting)
                    {
                        while (true)
                        {
                            if (!Sortting)
                            {
                                //开始删除作业
                                Deleting = true;
                                //从任务队列中移除任务
                                //当等待的任务超过3个的时候从任务队列中移除任务第一个已完成的任务
                                List<int> CompletedTaskIds = new List<int>();
                                for (int x = 0; x < TaskQueue.Count; x++)
                                {
                                    if (TaskQueue[x].Status == "已完成")
                                    {
                                        CompletedTaskIds.Add(TaskQueue[x].Id);
                                    }
                                }
                                if (CompletedTaskIds.Count > 3)
                                {
                                    ObservableCollection<AlgorithmListModel> TempTaskQueue = new ObservableCollection<AlgorithmListModel>();
                                    for (int i = 0; i < TaskQueue.Count; i++)
                                    {
                                        if (CompletedTaskIds[0] != TaskQueue[i].Id)
                                        {
                                            TempTaskQueue.Add(TaskQueue[i]);
                                        }
                                    }
                                    Application.Current.Dispatcher.Invoke((Action)delegate ()
                                    {
                                        TaskQueue = TempTaskQueue;
                                    });
                                    RaisePropertyChanged("TaskQueue");
                                }
                                //接收删除作业
                                Deleting = false;
                                Thread.Sleep(10);
                                break;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    LogTool.SaveSysLog(e.Message, "删除完成任务异常");
                }
            }
        }

        /// <summary>
        /// 更新对应的任务的数据
        /// </summary>
        /// <param name="OperTaskInfo"></param>
        private void UpdateTaskListForUI(AlgorithmListModel OperTaskInfo)
        {
            while (true)
            {
                if (!Sortting)
                {
                    ObservableCollection<AlgorithmListModel> TempTaskQueue = new ObservableCollection<AlgorithmListModel>();
                    for (int i = 0; i < TaskQueue.Count; i++)
                    {
                        TempTaskQueue.Add(TaskQueue[i]);
                    }
                    for (int i = 0; i < TempTaskQueue.Count; i++)
                    {
                        if (TempTaskQueue[i].OrderNo == OperTaskInfo.OrderNo)
                        {
                            TempTaskQueue[i].StartTime = OperTaskInfo.StartTime;
                            TempTaskQueue[i].EndTime = OperTaskInfo.EndTime;
                            TempTaskQueue[i].Status = OperTaskInfo.Status;
                            TempTaskQueue[i].Id = OperTaskInfo.Id;
                            TempTaskQueue[i].OrderNo = OperTaskInfo.OrderNo;
                            break;
                        }
                    }
                    Thread.Sleep(10);
                    Application.Current.Dispatcher.Invoke((Action)delegate ()
                    {
                        TaskQueue = TempTaskQueue;
                    });
                    RaisePropertyChanged("TaskQueue");
                    break;
                }
            }
        }

        /// <summary>
        /// 检测是否包含执行中的任务
        /// </summary>
        /// <returns></returns>
        private bool IsNotHaveInProgressTask()
        {
            for (int i = 0; i < TaskQueue.Count; i++)
            {
                if (TaskQueue[i].Status == "执行中")
                {
                    return false;
                }
            }
            return true;
        }

        /// <summary>
        /// 获取第一个非完成的任务
        /// </summary>
        /// <returns></returns>
        private AlgorithmListModel GetFirstTaks()
        {
            AlgorithmListModel FirstTaks = null;
            for (int i = 0; i < TaskQueue.Count; i++)
            {
                if (TaskQueue[i].Status != "已完成")
                {
                    FirstTaks = TaskQueue[i];
                    break;
                }
            }
            return FirstTaks;
        }

        /// <summary>
        /// 根据TaskNo获取对应任务描述
        /// </summary>
        /// <param name="TaskNo"></param>
        /// <returns></returns>
        private string GetTaskDesc(int TaskNo)
        {
            string TaskDesc = "";
            switch (TaskNo)
            {
                case 1:
                    TaskDesc = "将1#冷却室的铝料移至1#解垛位";
                    break;
                case 2:
                    TaskDesc = "将1#冷却室的铝料移至2#解垛位";
                    break;
                case 3:
                    TaskDesc = "将1#冷却室的铝料移至3#解垛位";
                    break;
                case 4:
                    TaskDesc = "将2#冷却室的铝料移至1#解垛位";
                    break;
                case 5:
                    TaskDesc = "将2#冷却室的铝料移至2#解垛位";
                    break;
                case 6:
                    TaskDesc = "将2#冷却室的铝料移至3#解垛位";
                    break;
                case 7:
                    TaskDesc = "将1#均质炉的铝料移至1#冷却室";
                    break;
                case 8:
                    TaskDesc = "将1#均质炉的铝料移至2#冷却室";
                    break;
                case 9:
                    TaskDesc = "将2#均质炉的铝料移至1#冷却室";
                    break;
                case 10:
                    TaskDesc = "将2#均质炉的铝料移至2#冷却室";
                    break;
                case 11:
                    TaskDesc = "将3#均质炉的铝料移至1#冷却室";
                    break;
                case 12:
                    TaskDesc = "将3#均质炉的铝料移至2#冷却室";
                    break;
                case 13:
                    TaskDesc = "将4#均质炉的铝料移至1#冷却室";
                    break;
                case 14:
                    TaskDesc = "将4#均质炉的铝料移至2#冷却室";
                    break;
                case 15:
                    TaskDesc = "将1#堆垛位的铝料移至1#均质炉";
                    break;
                case 16:
                    TaskDesc = "将1#堆垛位的铝料移至2#均质炉";
                    break;
                case 17:
                    TaskDesc = "将1#堆垛位的铝料移至3#均质炉";
                    break;
                case 18:
                    TaskDesc = "将1#堆垛位的铝料移至4#均质炉";
                    break;
                case 19:
                    TaskDesc = "将2#堆垛位的铝料移至1#均质炉";
                    break;
                case 20:
                    TaskDesc = "将2#堆垛位的铝料移至2#均质炉";
                    break;
                case 21:
                    TaskDesc = "将2#堆垛位的铝料移至3#均质炉";
                    break;
                case 22:
                    TaskDesc = "将2#堆垛位的铝料移至4#均质炉";
                    break;
                case 23:
                    TaskDesc = "将1#隔条仓的空隔条架子移至隔条总仓";
                    break;
                case 24:
                    TaskDesc = "将3#隔条仓的隔条移至1#隔条仓";
                    break;
                case 25:
                    TaskDesc = "将隔条总仓的空隔条架子移至3#隔条仓";
                    break;
                case 26:
                    TaskDesc = "将2#隔条仓的空隔条架子移至隔条总仓";
                    break;
                case 27:
                    TaskDesc = "将3#隔条仓的隔条移至2#隔条仓";
                    break;
                case 28:
                    TaskDesc = "搬运1#解垛位底部隔条";
                    break;
                case 29:
                    TaskDesc = "搬运2#解垛位底部隔条";
                    break;
                case 30:
                    TaskDesc = "搬运3#解垛位底部隔条";
                    break;
                case -1:
                    TaskDesc = "错误";
                    break;
                default:
                    TaskDesc = "无任务";
                    break;
            }
            return TaskDesc;
        }
        #endregion 3#线程的相关方法

        #region 模式切换的相关方法
        /// <summary>
        /// 根据程序块描述获取对应的值
        /// </summary>
        /// <param name="TagDesc"></param>
        /// <returns></returns>
        private string GetValueByTagDesc(string TagDesc)
        {
            TagInfo ExecutingTaskTagInfo = new TagInfo();
            ExecutingTaskTagInfo.TagDesc = TagDesc;
            ExecutingTaskTagInfo = DapperTools.Query<TagInfo>("select * from TagInfo WHERE TagDesc = @TagDesc", ExecutingTaskTagInfo);
            return GetSiemensValByAddressAndType(ExecutingTaskTagInfo.Address, ExecutingTaskTagInfo.ValueType);
        }
        /// <summary>
        /// 根据任务描述获取对应序号
        /// </summary>
        /// <param name="taskDesc"></param>
        /// <returns></returns>
        private int GetTaskSNoByTaskDesc(string taskDesc)
        {
            switch (taskDesc)
            {
                case "将1#冷却室的铝料移至1#解垛位":
                    return 1;
                case "将1#冷却室的铝料移至2#解垛位":
                    return 2;
                case "将1#冷却室的铝料移至3#解垛位":
                    return 3;
                case "将2#冷却室的铝料移至1#解垛位":
                    return 4;
                case "将2#冷却室的铝料移至2#解垛位":
                    return 5;
                case "将2#冷却室的铝料移至3#解垛位":
                    return 6;
                case "将1#均质炉的铝料移至1#冷却室":
                    return 7;
                case "将1#均质炉的铝料移至2#冷却室":
                    return 8;
                case "将2#均质炉的铝料移至1#冷却室":
                    return 9;
                case "将2#均质炉的铝料移至2#冷却室":
                    return 10;
                case "将3#均质炉的铝料移至1#冷却室":
                    return 11;
                case "将3#均质炉的铝料移至2#冷却室":
                    return 12;
                case "将4#均质炉的铝料移至1#冷却室":
                    return 13;
                case "将4#均质炉的铝料移至2#冷却室":
                    return 14;
                case "将1#堆垛位的铝料移至1#均质炉":
                    return 15;
                case "将1#堆垛位的铝料移至2#均质炉":
                    return 16;
                case "将1#堆垛位的铝料移至3#均质炉":
                    return 17;
                case "将1#堆垛位的铝料移至4#均质炉":
                    return 18;
                case "将2#堆垛位的铝料移至1#均质炉":
                    return 19;
                case "将2#堆垛位的铝料移至2#均质炉":
                    return 20;
                case "将2#堆垛位的铝料移至3#均质炉":
                    return 21;
                case "将2#堆垛位的铝料移至4#均质炉":
                    return 22;
                case "将1#隔条仓的空隔条架子移至隔条总仓":
                    return 23;
                case "将3#隔条仓的隔条移至1#隔条仓":
                    return 24;
                case "将隔条总仓的空隔条架子移至3#隔条仓":
                    return 25;
                case "将2#隔条仓的空隔条架子移至隔条总仓":
                    return 26;
                case "将3#隔条仓的隔条移至2#隔条仓":
                    return 27;
                case "搬运1#解垛位底部隔条":
                    return 28;
                case "搬运2#解垛位底部隔条":
                    return 29;
                case "搬运3#解垛位底部隔条":
                    return 30;
                default:
                    return -1;
            }
        }

        /// <summary>
        /// 确认所有的任务对应标签都为false,才能验证通过
        /// </summary>
        private bool IsAllPass()
        {
            try
            {
                string ExecutingTaskDesc = "";
                for (int i = 0; i < TaskQueue.Count; i++)
                {
                    if (TaskQueue[i].Status == "执行中")
                    {
                        ExecutingTaskDesc = TaskQueue[i].TaskDesc;
                        break;
                    }
                }
                //如果有正在执行的任务
                if (ExecutingTaskDesc != "")
                {
                    //验证标签是不是对，如果不对，变红色提醒
                    int FalseTaskCount = 0;
                    for (int j = 0; j < ListeningAllTagQueue.Count; j++)
                    {
                        switch (ListeningAllTagQueue[j].TagDesc)
                        {
                            case "控制系统确认任务完成":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                    FalseTaskCount++;
                                }
                                break;
                            case "任务指令执行完成":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                    FalseTaskCount++;
                                }
                                break;
                            //case "执行完成的标签名":
                            //    if (ListeningAllTagQueue[j].Value == null || ListeningAllTagQueue[j].Value != GetTaskSNoByTaskDesc(ExecutingTaskDesc).ToString())
                            //    {
                            //        IsPass = false;
                            //        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                            //    }
                            //    break;

                            case "将1#冷却室的铝料移至1#解垛位":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将1#冷却室的铝料移至2#解垛位":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将1#冷却室的铝料移至3#解垛位":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将2#冷却室的铝料移至1#解垛位":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将2#冷却室的铝料移至2#解垛位":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将2#冷却室的铝料移至3#解垛位":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将1#均质炉的铝料移至1#冷却室":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将1#均质炉的铝料移至2#冷却室":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将2#均质炉的铝料移至1#冷却室":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将2#均质炉的铝料移至2#冷却室":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将3#均质炉的铝料移至1#冷却室":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将3#均质炉的铝料移至2#冷却室":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将4#均质炉的铝料移至1#冷却室":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将4#均质炉的铝料移至2#冷却室":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将1#堆垛位的铝料移至1#均质炉":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将1#堆垛位的铝料移至2#均质炉":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将1#堆垛位的铝料移至3#均质炉":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将1#堆垛位的铝料移至4#均质炉":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将2#堆垛位的铝料移至1#均质炉":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将2#堆垛位的铝料移至2#均质炉":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将2#堆垛位的铝料移至3#均质炉":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将2#堆垛位的铝料移至4#均质炉":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "搬运1#解垛位底部隔条":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "搬运2#解垛位底部隔条":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "搬运3#解垛位底部隔条":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将1#隔条仓的空隔条架子移至隔条总仓":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将3#隔条仓的隔条移至1#隔条仓":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将隔条总仓的空隔条架子移至3#隔条仓":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将2#隔条仓的空隔条架子移至隔条总仓":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            case "将3#隔条仓的隔条移至2#隔条仓":
                                if (ListeningAllTagQueue[j].TagDesc == ExecutingTaskDesc)
                                {
                                    if (ListeningAllTagQueue[j].Value == "True")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                else
                                {
                                    if (ListeningAllTagQueue[j].Value == "False")
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                        FalseTaskCount++;
                                    }
                                    else
                                    {
                                        ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                    }
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    if (FalseTaskCount != 32)
                    {
                        IsPass = false;
                        IsCheck = false;
                    }
                    else
                    {
                        IsPass = true;
                    }
                }
                //如果没有正在执行的任务
                else
                {
                    int FalseTaskCount = 0;
                    for (int j = 0; j < ListeningAllTagQueue.Count; j++)
                    {
                        switch (ListeningAllTagQueue[j].TagDesc)
                        {
                            case "控制系统确认任务完成":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "任务指令执行完成":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            //case "执行完成的标签名":

                            //    FalseTaskCount++;

                            //    break;

                            case "将1#冷却室的铝料移至1#解垛位":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将1#冷却室的铝料移至2#解垛位":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将1#冷却室的铝料移至3#解垛位":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将2#冷却室的铝料移至1#解垛位":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将2#冷却室的铝料移至2#解垛位":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将2#冷却室的铝料移至3#解垛位":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将1#均质炉的铝料移至1#冷却室":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将1#均质炉的铝料移至2#冷却室":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将2#均质炉的铝料移至1#冷却室":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                break;
                            case "将2#均质炉的铝料移至2#冷却室":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将3#均质炉的铝料移至1#冷却室":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将3#均质炉的铝料移至2#冷却室":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将4#均质炉的铝料移至1#冷却室":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将4#均质炉的铝料移至2#冷却室":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将1#堆垛位的铝料移至1#均质炉":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将1#堆垛位的铝料移至2#均质炉":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将1#堆垛位的铝料移至3#均质炉":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将1#堆垛位的铝料移至4#均质炉":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将2#堆垛位的铝料移至1#均质炉":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将2#堆垛位的铝料移至2#均质炉":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将2#堆垛位的铝料移至3#均质炉":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将2#堆垛位的铝料移至4#均质炉":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "搬运1#解垛位底部隔条":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "搬运2#解垛位底部隔条":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "搬运3#解垛位底部隔条":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将1#隔条仓的空隔条架子移至隔条总仓":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将3#隔条仓的隔条移至1#隔条仓":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将隔条总仓的空隔条架子移至3#隔条仓":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将2#隔条仓的空隔条架子移至隔条总仓":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            case "将3#隔条仓的隔条移至2#隔条仓":
                                if (ListeningAllTagQueue[j].Value == "False")
                                {
                                    FalseTaskCount++;
                                    ListeningAllTagQueue[j].SomeConditionalProperty = false;
                                }
                                else
                                {
                                    ListeningAllTagQueue[j].SomeConditionalProperty = true;
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    if (FalseTaskCount != 32)
                    {
                        IsPass = false;
                        IsCheck = false;
                    }
                    else
                    {
                        IsPass = true;
                    }
                }
            }
            catch (Exception e)
            {
                LogTool.SaveSysLog(e.Message, "手动转自动验证异常");
            }
            return IsPass;
        }

        #endregion 模式切换的相关方法

        #region 获取标签信息的多态方法，读写标签值的方法

        /// <summary>
        /// 从监控的全部程序块中获取对应的程序块。
        /// </summary>
        private TagInfo GetTagInfoByTagDesc(string TagDesc)
        {
            TagInfo tag = null;
            foreach (TagInfo item in ListeningAllTagQueue)
            {
                if (item.TagDesc == TagDesc)
                {
                    tag = item;
                    break;
                }
            }
            return tag;
        }

        /// <summary>
        /// 获取标签信息。 
        /// </summary>
        private TagInfo GetTagInfoByTagDesc(AlgorithmListModel algorithmListModel)
        {
            TagInfo tagInfo = null;
            foreach (TagInfo item in ListeningAllTagQueue)
            {
                if (item.TagDesc == algorithmListModel.TaskDesc)
                {
                    tagInfo = item;
                    break;
                }
            }
            return tagInfo;
        }
        /// <summary>
        /// 根据类型使用不同方式获取值西门子专用。
        /// </summary>
        private string GetSiemensValByAddressAndType(string Address, string ValueType)
        {
            if (ValueType == "Bool")
            {
                return siemens.ReadBool(Address).Content.ToString();
            }
            else if (ValueType == "DInt")
            {
                return siemens.ReadInt32(Address).Content.ToString();
            }
            else if (ValueType == "Int")
            {
                return siemens.ReadInt16(Address).Content.ToString();
            }
            else if (ValueType == "String")
            {
                return siemens.ReadString(Address).Content;
            }
            return "无法识别的数据类型";
        }
        /// <summary>
        /// 根据类型使用不同方式写入值 西门子专用。
        /// </summary>
        private bool WriteSiemensValByAddressAndType(string Address, string ValueType, string Value)
        {
            OperateResult operateResult = null;
            if (ValueType == "Bool")
            {
                operateResult = siemens.Write(Address, bool.Parse(Value.ToLower()));
            }
            else if (ValueType == "DInt")
            {
                operateResult = siemens.Write(Address, Int32.Parse(Value));
            }
            else if (ValueType == "Int")
            {
                operateResult = siemens.Write(Address, float.Parse(Value));
            }
            else if (ValueType == "String")
            {
                operateResult = siemens.Write(Address, Value);
            }
            return operateResult.IsSuccess;
        }
        #endregion
        #region 远程半自动模式
        /// <summary>
        /// 当前任务
        /// </summary>
        private string CurrentTask = "";

        /// <summary>
        /// 远程半自动模式 取消命令
        /// </summary>
        /// <param name="obj"></param>
        private void CancelHandler(object obj)
        {
            Messenger.Default.Send<NotificationMessage>(new NotificationMessage(this, "HideRemoteSemiAutomaticWindows"));
        }

        /// <summary>
        /// 更改当前任务
        /// </summary>
        /// <param name="obj"></param>
        private void ChangeCurrentTaskHandler(object obj)
        {
            CurrentTask = obj.ToString();
        }

        /// <summary>
        /// 远程半自动模式 下达命令
        /// </summary>
        /// <param name="obj"></param>
        private void ReleaseHandler(object obj)
        {
            if (CurrentTask != "")
            {
                if (IsAutomatic)
                {
                    WindowManager.ShowWarning("警告", "请关闭自动控制！");
                }
                else
                {
                    string NotTrueTag = "";
                    for (int j = 0; j < ListeningAllTagQueue.Count; j++)
                    {
                        switch (ListeningAllTagQueue[j].TagDesc)
                        {
                            case "将1#冷却室的铝料移至1#解垛位":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将1#冷却室的铝料移至2#解垛位":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将1#冷却室的铝料移至3#解垛位":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将2#冷却室的铝料移至1#解垛位":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将2#冷却室的铝料移至2#解垛位":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将2#冷却室的铝料移至3#解垛位":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将1#均质炉的铝料移至1#冷却室":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将1#均质炉的铝料移至2#冷却室":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将2#均质炉的铝料移至1#冷却室":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将2#均质炉的铝料移至2#冷却室":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将3#均质炉的铝料移至1#冷却室":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将3#均质炉的铝料移至2#冷却室":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将4#均质炉的铝料移至1#冷却室":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将4#均质炉的铝料移至2#冷却室":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将1#堆垛位的铝料移至1#均质炉":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将1#堆垛位的铝料移至2#均质炉":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将1#堆垛位的铝料移至3#均质炉":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将1#堆垛位的铝料移至4#均质炉":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将2#堆垛位的铝料移至1#均质炉":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将2#堆垛位的铝料移至2#均质炉":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将2#堆垛位的铝料移至3#均质炉":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将2#堆垛位的铝料移至4#均质炉":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "搬运1#解垛位底部隔条":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "搬运2#解垛位底部隔条":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "搬运3#解垛位底部隔条":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将1#隔条仓的空隔条架子移至隔条总仓":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将3#隔条仓的隔条移至1#隔条仓":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将隔条总仓的空隔条架子移至3#隔条仓":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将2#隔条仓的空隔条架子移至隔条总仓":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            case "将3#隔条仓的隔条移至2#隔条仓":
                                if (ListeningAllTagQueue[j].Value != "False")
                                {
                                    NotTrueTag += "【" + ListeningAllTagQueue[j].TagDesc + "】、";
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    if (NotTrueTag != "")
                    {
                        NotTrueTag = NotTrueTag.Substring(0, NotTrueTag.Length - 1);
                        WindowManager.ShowWarning("警告", "请保证30个任务的标签都是False，现在值不是False的标签有" + NotTrueTag + "。");
                    }
                    else
                    {
                        //获取任务对应的程序块，并写入PLC值
                        TagInfo FirstTaskTagInfo = GetTagInfoByTagDesc(CurrentTask);
                        //将任务对应标签赋值true
                        //向PLC下达任务
                        bool WriteResult = WriteSiemensValByAddressAndType(FirstTaskTagInfo.Address, FirstTaskTagInfo.ValueType, "True");
                        if (WriteResult)
                        {
                            //如果任务已经执行，则监控执行状态反馈
                            while (true)
                            {
                                TagInfo SuccessTaskNoTagInfoCondition = new TagInfo();
                                SuccessTaskNoTagInfoCondition.TagDesc = "执行完成的标签名";
                                string SuccessTaskNoAddress = DapperTools.Query<TagInfo>("select * from TagInfo WHERE TagDesc = @TagDesc", SuccessTaskNoTagInfoCondition).Address;
                                string SuccessTaskInfo = siemens.ReadInt32(SuccessTaskNoAddress).Content.ToString();
                                string SuccessTaskNoAddress1 = DapperTools.Query<TagInfo>("select * from TagInfo WHERE TagDesc = '任务指令执行完成'", SuccessTaskNoTagInfoCondition).Address;
                                bool SuccessTaskInfo1 = siemens.ReadBool(SuccessTaskNoAddress1).Content;
                                bool taskIsComplete = false;
                                if (GetTaskDesc(int.Parse(SuccessTaskInfo)) == CurrentTask)
                                {
                                    taskIsComplete = true;
                                }
                                if (SuccessTaskInfo != null &&
                                    SuccessTaskInfo != "0" &&
                                    SuccessTaskInfo1 &&
                                    taskIsComplete)
                                {
                                    TagInfo SystemConfirmCompleteTag = GetTagInfoByTagDesc("控制系统确认任务完成");
                                    //当收到PLC执行完成后，控制系统确认完成。
                                    bool ConfirmCompletionWriteResult = WriteSiemensValByAddressAndType(SystemConfirmCompleteTag.Address, SystemConfirmCompleteTag.ValueType, "True");
                                    switch (CurrentTask)
                                    {
                                        case "将1#冷却室的铝料移至1#解垛位":
                                            SaTask1Checked = false;
                                            break;
                                        case "将1#冷却室的铝料移至2#解垛位":
                                            SaTask2Checked = false;
                                            break;
                                        case "将1#冷却室的铝料移至3#解垛位":
                                            SaTask3Checked = false;
                                            break;
                                        case "将2#冷却室的铝料移至1#解垛位":
                                            SaTask4Checked = false;
                                            break;
                                        case "将2#冷却室的铝料移至2#解垛位":
                                            SaTask5Checked = false;
                                            break;
                                        case "将2#冷却室的铝料移至3#解垛位":
                                            SaTask6Checked = false;
                                            break;
                                        case "将1#均质炉的铝料移至1#冷却室":
                                            SaTask7Checked = false;
                                            break;
                                        case "将1#均质炉的铝料移至2#冷却室":
                                            SaTask8Checked = false;
                                            break;
                                        case "将2#均质炉的铝料移至1#冷却室":
                                            SaTask9Checked = false;
                                            break;
                                        case "将2#均质炉的铝料移至2#冷却室":
                                            SaTask10Checked = false;
                                            break;
                                        case "将3#均质炉的铝料移至1#冷却室":
                                            SaTask11Checked = false;
                                            break;
                                        case "将3#均质炉的铝料移至2#冷却室":
                                            SaTask12Checked = false;
                                            break;
                                        case "将4#均质炉的铝料移至1#冷却室":
                                            SaTask13Checked = false;
                                            break;
                                        case "将4#均质炉的铝料移至2#冷却室":
                                            SaTask14Checked = false;
                                            break;
                                        case "将1#堆垛位的铝料移至1#均质炉":
                                            SaTask15Checked = false;
                                            break;
                                        case "将1#堆垛位的铝料移至2#均质炉":
                                            SaTask16Checked = false;
                                            break;
                                        case "将1#堆垛位的铝料移至3#均质炉":
                                            SaTask17Checked = false;
                                            break;
                                        case "将1#堆垛位的铝料移至4#均质炉":
                                            SaTask18Checked = false;
                                            break;
                                        case "将2#堆垛位的铝料移至1#均质炉":
                                            SaTask19Checked = false;
                                            break;
                                        case "将2#堆垛位的铝料移至2#均质炉":
                                            SaTask20Checked = false;
                                            break;
                                        case "将2#堆垛位的铝料移至3#均质炉":
                                            SaTask21Checked = false;
                                            break;
                                        case "将2#堆垛位的铝料移至4#均质炉":
                                            SaTask22Checked = false;
                                            break;
                                        case "将1#隔条仓的空隔条架子移至隔条总仓":
                                            SaTask23Checked = false;
                                            break;
                                        case "将3#隔条仓的隔条移至1#隔条仓":
                                            SaTask24Checked = false;
                                            break;
                                        case "将隔条总仓的空隔条架子移至3#隔条仓":
                                            SaTask25Checked = false;
                                            break;
                                        case "将2#隔条仓的空隔条架子移至隔条总仓":
                                            SaTask26Checked = false;
                                            break;
                                        case "将3#隔条仓的隔条移至2#隔条仓":
                                            SaTask27Checked = false;
                                            break;
                                        case "搬运1#解垛位底部隔条":
                                            SaTask28Checked = false;
                                            break;
                                        case "搬运2#解垛位底部隔条":
                                            SaTask29Checked = false;
                                            break;
                                        case "搬运3#解垛位底部隔条":
                                            SaTask30Checked = false;
                                            break;
                                        default:
                                            break;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                WindowManager.ShowWarning("警告", "请选择要下达的任务！！！");
            }
        }
        #endregion
    }
}
